nginx 配置

nginx 配置(总共100行

nginx文件结构

...              #全局块

 

events {         #events

   ...

}

 

http      #http

{

    ...   #http全局块

    server        #server

    { 

        ...       #server全局块

        location [PATTERN]   #location

        {

            ...

        }

        location [PATTERN] 

        {

            ...

        }

    }

    server

    {

      ...

    }

    ...     #http全局块

}

 

====================================

1、全局块:配置影响nginx全局的指令。一般有运行nginx服务器的用户组,nginx进程pid存放路径,日志存放路径,配置文件引入,允许生成worker process数等。

2、events块:配置影响nginx服务器或与用户的网络连接。有每个进程的最大连接数,选取哪种事件驱动模型处理连接请求,是否允许同时接受多个网路连接,开启多个网络连接序列化等。

3、http块:可以嵌套多个server,配置代理,缓存,日志定义等绝大多数功能和第三方模块的配置。如文件引入,mime-type定义,日志自定义,是否使用sendfile传输文件,连接超时时间,单连接请求数等。

4、server块:配置虚拟主机的相关参数,一个http中可以有多个server。

5、location块:配置请求的路由,以及各种页面的处理情况。

 

 

http      #http

{

 

server {    #server

     listen       80;

    server_name  localhost;

         location / {                            #location

              root   html; //目录

            index  index.html index.htm;

      }

        error_page   500 502 503 504  /50x.html;

location = /50x.html {    #location

           root   html;

          }

 

 

#location ~ \.php$ {    //#将PHP脚本代理到在127.0.0.1:80上监听的Apache   #location

        #    proxy_pass   http://127.0.0.1;

        #}

 

#location ~ \.php$ { #将PHP脚本传递给在127.0.0.1:9000上监听的FastCGI服务器   #location

              #    root           html;

             #    fastcgi_pass   127.0.0.1:9000;

             #    fastcgi_index  index.php;

             #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;

            #    include        fastcgi_params;

           #}

 

另外一个//另一个使用基于IP,名称和端口配置的虚拟主机

#另一个使用基于IP,名称和端口配置的虚拟主机
    #

 82     # another virtual host using mix of IP-, name-, and port-based configuration

 83     #

 84     #server {

 85     #    listen       8000;

 86     #    listen       somename:8080;

 87     #    server_name  somename  alias  another.alias;

 88

 89     #    location / {

 90     #        root   html;

 91     #        index  index.html index.htm;

 92     #    }

 93     #}

 

}

posted @ 2017-12-01 11:20  克维拉  阅读(173)  评论(0编辑  收藏  举报