nginx-源码安装以及配置文件

nginx安装

1. 安装 Nginx 所需的 pcre
yum install -y pcre-devel
2. 安装 Nginx
( 1 ) 检查并安装 Nginx 基础依赖包 pcre-devel openssl-devel
# rpm -qa | egrep 'pcre-devel | openssl-devel'
( 2 ) 安装 openssl-devel
yum install -y openssl-devel
( 3 ) 开始安装 Nginx
useradd nginx -s /sbin/nologin -M ./configure --user=nginx group=nginx \ 
--prefix=/usr/local/nginx \
--with-http_stub_status_module \ 
--with-http_ssl_module 
# 编译并安装 
make && make install
( 4) nginx 提供 SysV init 脚本
# vim /usr/lib/systemd/system/nginx.service 
[Unit] 
Description=nginx - high performance web server
Documentation=http://nginx.org/en/docs/ 
After=network.target remote-fs.target nss-lookup.target 
[Service] 
Type=forking 
PIDFile=/run/nginx.pid 
ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf ExecReload=/bin/kill -s HUP $MAINPID 
ExecStop=/bin/kill -s QUIT $MAINPID 
PrivateTmp=true 
[Install] 
WantedBy=multi-user.target

5.启动服务

systemctl start nginx

配置基于域名的虚拟主机
 

在/etc/nginx/conf.d下创建xxx.conf,内容为:

server{

        listen 80;
        server_name www.jianwen.com;
        location / {
          root /abc;
          index index.html index.htm;

}
}

创建/abc文件夹,在此文件夹下创建并编写index.html。

配置nginx基于用户和地址的访问控制。

基于主机
在配置文件中添加 allow  允许某些主机,deny 拒绝某些主机。

基于用户
在server下添加
 

auth_basic "nginx access test!";
            auth_basic_user_file /etc/nginx/conf.d/passwd;

nginx的rewrite

location / {
 root html; 
index index.html index.htm; 
if (!-f $request_filename) { 
rewrite /.* /err.html permanent; (permanent表示永久的重定向到这个页面) 
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值