1. 从一张工程Nginx配置表开始

156 阅读1分钟

实践出真知,从一张工程Nginx配置表看一下具体配置~

#user  DEYI;
worker_processes  5;

error_log  log/error.log notice;
#error_log  log/error.log  debug;
#error_log  log/error.log  info;

pid        log/nginx.pid;

events {
    use epoll;
    worker_connections  51200;
}
worker_rlimit_nofile 51200;

http {
    include       mime.types;
    default_type  application/octet-stream;
    charset utf-8;
    include conf.d/*.conf;

    client_header_buffer_size 4k;
    large_client_header_buffers 4 32k;
    client_max_body_size 2m;
    client_body_buffer_size 1024k;

    open_file_cache max=5000 inactive=60;

    log_format main '$remote_addr - $remote_user [$time_local]  '
    '"$request" $status $request_length $request_time $body_bytes_sent '
    '"$http_referer" "$http_user_agent" $server_addr $upstream_addr $host $upstream_cache_status $HTTP_DIDI_HEADER_RID';

    access_log  log/access.log  main;

    sendfile        on;
    tcp_nopush     on;

#keepalive_timeout  0;
    keepalive_timeout  120;
    reset_timedout_connection on;

#gzip  on;
#our client does not support gzip
    gzip off;
    gzip_min_length  1000;
    gzip_buffers     16 8k;
    gzip_http_version 1.1;
    gzip_comp_level 2;
    gzip_types       text/plain application/x-javascript text/css application/xml;
    gzip_vary off;


    set_real_ip_from   10.0.0.0/8;
    real_ip_header   X-Real-IP;

    upstream benefit_backend {
        server 127.0.0.1:8018;
    }

    server {
        listen       8000;
        root /home/DEYI/webroot/static/I18n-platform;
        server_name _;

        location ^~ /static {
            alias /home/DEYI/webroot/static/I18n-platform/static;
        }
        location = /index.html {
            alias /home/DEYI/webroot/static/I18n-platform/index.html;
        }

        location ~* /i18n/gw/v2/ {
            add_header Cache-Control 'max-age=0';
            proxy_pass http://1000000000000000;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header Cookie $http_cookie;
        }

        location ~* /i18n/ {
            proxy_pass http://100000000000;
            add_header Cache-Control 'max-age=0';
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header Cookie $http_cookie;
        }

        location ~* /copywriter/ {
            add_header Cache-Control 'max-age=0';
            proxy_pass http://10000000000;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header Cookie $http_cookie;
        }

        location / {
           try_files $uri $uri/ /index.html;
        }

        error_page 404 /404.html;
            location = /40x.html {
        }

        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }
    }

}