您的位置:首页 > 运维架构 > Nginx

nginx配置完全解读

2016-09-09 15:57 761 查看
#user  nobody;

worker_processes  1;

#error_log  logs/error.log;

#error_log  logs/error.log  notice;

#error_log  logs/error.log  info;

#include (引入配置文件,支持相对路径)

#pid        logs/nginx.pid;

events {

    #accept_mutex  on/off; 设置网络连接序列化

    #multi_accept  on/off; 设置每个worker_processes是否允许处理多个请求(默认off)

    worker_connections  2048; 设置每一个worker_processes同时开启的最大连接数

}

http {

    #include mime.types; 从外部引入mime_types文件

    #default_type application/octet-stream; 默认处理前端请求的MIME类型

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

    #                  '$status $body_bytes_sent "$http_referer" '

    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;服务日志,main是直接引用上边的日志格式

    

    add_header Access-Control-Allow-Origin *;

    add_header Access-Control-Allow-Headers X-Requested-With;

    add_header Access-Control-Allow-Methods GET,POST,OPTIONS;

    client_max_body_size 5M;

    client_body_buffer_size 128k;

    fastcgi_buffers 8 128k;

    send_timeout 60;

    #sendfile      on; 允许sendfile方式发送文件

    #sendfile_max_chunk size;  size:0,无限制;  >0 每个work prodcess传输的最大值

    #tcp_nopush     on;

    #keepalive_timeout  timeout[header_timeout]; 服务器端的连接时间默认75s

           # 例如:keepalive_timeout 120s 100s;服务端保持120s连接,客户端应答头Keep-Alive域超时时间100s

   #keepalive_requests number;nginx服务端和用户端建立连接后,客户端向nginx服务发送请求的次数。默认100

 

 

    #设置缓存路径

    proxy_cache_path /www/ levels=1:2 keys_zone=Z:10m inactive=1m max_size=30g;

    #gzip  on;

   server {

        listen       80;

        server_name  localhost;

        location / {

           

            #root   /www/;

            #expires max;

            #proxy_store on;

            #proxy_store_access user:rw group:rw all:rw;

            #proxy_temp_path /www/;

            proxy_cache Z;

            #把返回为200的请求页面缓存起来,1分钟后过期

            proxy_cache_valid 200 1m;

            #expires max;

            #include proxy.conf;

    

            if ( !-e $request_filename) {

            proxy_pass  http://127.0.0.1:8080;
            }

           

           #proxy_pass   http://127.0.0.1:8080;
        }

        

        error_page   500 502 503 504  /50x.html;

        location = /50x.html {

            root   html;

        }

        #配置Nginx状态的地址

        location /NginxStatus {   

            stub_status on;   

            access_log on;   

            auth_basic "NginxStatus";   

            auth_basic_user_file conf/htpasswd;   

        }

    }

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: