Nginx配置详解

上一篇博文已经讲了LNMP环境搭建详细教程,安装好后首先需要了解nginx的配置文件:/usr/local/nginx/conf/nginx.conf,我将配置文件内的注释项和暂时用不到的都去掉了,这样看起来更加清爽:

#全局区
worker_processes 1; #有1个工作的子进程,会占用CPU,可自由设置,一般设置为:CPU数*核数,如果想查看工作中的进程,可以使用命令:ps aux|grep nginx
Event {
#一般是配置nginx连接的特性    worker_connections 1024; #这是指一个worker能同时允许多少连接 } http { #这是配置http服务器的主要段
   #日志管理默认为main格式,记录的内容为: 
   #远程IP:$remote_addr
   #用户时间:$remote_user [$time_local]
   #请求方法(如GET/POST):$request
   #请求状态:$status
   #请求体body长度:$body_bytes_sent
   #referer来源信息:$http_referer
   #用户代理/蜘蛛:$http-user-agent
   #被转发的请求的原始IP:$http_x_forwarded_for
   log_format main '$remote_addr - $remote_user [$time_local] "$request" ' 
             '$status $body_bytes_sent "$http_referer" '
                   '"$http_user_agent" "$http_x_forwarded_for"'; #默认的日志配置
    
  server {
#这里整个server的意思就是当你在浏览器中请求127.0.0.1这个地址时,location匹配后定位到/usr/local/nginx/html/index.html

listen
80; #监听端口 server_name 127.0.0.1; #监听域名      access_log logs/host.access.log main; #开启日志
location
/ { #定位,把特殊的路径或文件再次定位
       root html; #根目录定位,可以使用相对路径,此处所说的根目录是
/usr/local/nginx目录下,也可使用绝对路径定位,如你的项目在/var/www/html/目录下,就可以改为root/var/www/html/ index index.html index.htm; }
     location
~ \.php$ { #nginx转发PHP请求,碰到.php文件,把根目录定位到html,把请求转交给9000端口PHP进程, 并告诉PHP进程当前的请求的脚本是/scripts$fastcgi_script_name        root html;        fastcgi_pass 127.0.0.1:9000; #默认PHP9000端口        fastcgi_index index.php;        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;        include fastcgi_params;      }
} }

 

posted @ 2018-07-20 17:59  我是东山呀  阅读(1337)  评论(0编辑  收藏  举报