nginx简单配置详解

安装nginx

wget http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm

2 安装这个rpm

rpm -ivhnginx-release-centos-6-0.el6.ngx.noarch.rpm

安装过程中会出现错误提示:

warning:nginx-release-centos-6-0.el6.ngx.noarch.rpm: Header V4 RSA/SHA1 Signature, keyID 7bd9bf62: NOKEY

忽略即可

3 开始正式安装nginx

yum install nginx

会显示一大堆信息:Is this ok [y/N]:

输入y,屏幕滚了一会之后就安装完毕,最后提示“Complete!”就是安完了。

4 nginx的几个默认目录

输入命令: whereis nginx

nginx: /usr/sbin/nginx /etc/nginx/usr/share/nginx

1) 配置所在目录:/etc/nginx/

2) PID目录:/var/run/nginx.pid

3) 错误日志:/var/log/nginx/error.log

4) 访问日志:/var/log/nginx/access.log

5) 默认站点目录:/usr/share/nginx/html

[root@www vfast]# vi /etc/nginx/nginx.conf

 

 

user nginx; ---用户

worker_processes  1; --可设置成cpu核数

 

error_log /var/log/nginx/error.log warn; --错误日志

pid       /var/run/nginx.pid;

 

 

events {

   worker_connections  1024;--设置连接数最大值

}

 

http {

   include      /etc/nginx/mime.types;

   default_type application/octet-stream;

 

   log_format  main  '$remote_addr - $remote_user [$time_local]"$request" '

                      '$status $body_bytes_sent"$http_referer" '

                     '"$http_user_agent" "$http_x_forwarded_for"';

日志类型:$remote_addr 客户端IP地址

                $remote_user 客户端用户名称

                $time_local 访问时间和时区

                $request 请求的URLhttp协议

                $status 记录请求状态,成功为200

                $body_bytes_sent 给客户端文件主体大小

                $http_referer 从哪个页面链接过来的

                $http_user_agent 用户浏览器

                $http_x_forwarded_for

               

 

 

   access_log /var/log/nginx/access.log  main; 访问日志路径和格式

 

   sendfile        on;

   #tcp_nopush     on;

   keepalive_timeout  65;保持活动超时时间,超过之后服务器会关闭连接

 

   #gzip  on;

 

   include /etc/nginx/conf.d/*.conf;

   server{

      listen 80; --监听端口

     server_name  www.charles.com; --域名或者是IP地址

     location / {                               location可以理解为匹配 /代表匹配所有

               root /tmp/www;      网站根路径该root不是用户是根的意思后接网站路径

               index index.html index.htm;

      }

      location ~*\.php$ {                location可以理解为匹配 ~*代表不区分大小写

              proxy_pass http://192.168.1.106; .Php结尾的转发给后面的IP

    }

     error_page 404        /404.html; 定义错误日志

     location =/404.html{

     root /tmp/www;

     }

 

}

 

   server{

      listen 80;

     server_name www.vfast.com;

     location / {

               root /tmp/vfast;

               index index.html index.htm;

    }

 

     error_page 404       /404.html;

     location =/404.html{

     root /tmp/vfast;

     }

}

 

#      error_page 404       /404.html;

#     location =/404.html{

#     root /tmp/vfast

#     }

}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值