nginx 配置示例

"nginx 配置示例"

Posted by Mr Chang on December 21, 2017      @ Views:

转发配置示例

worker_processes  1;

user root;

events {
    worker_connections  10240;
}


http {
    include       mime.types;
    default_type  application/octet-stream;
    client_max_body_size 200M;
    client_header_buffer_size 8k;
    large_client_header_buffers 8 16k;

    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  on;

    sendfile        on;

    keepalive_timeout  300;

    gzip  on;
    gzip_http_version 1.0;
    gzip_disable "MSIE [1-6].";
    gzip_types text/plain application/x-javascript text/css text/javascript;


    server {
        listen       80;
        server_name  demo.test.com; //测试域名
        client_header_buffer_size 8k;
        large_client_header_buffers 8 16k;


        root   /root/static/qsz/admin; //默认资源存放路径
        index login.html;

        access_log  /root/static/qsz/admin/log/host.access.log   main;

        location ~* base.js$ // base.js 单独的规则
        {
            root /root/static/qsz/admin; 

        }

        location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|woff2|woff|ttf)$ //已这些后缀结尾的规则
        {
            root /root/static/qsz/public; //存放路径
            if (-f $request_filename) {
                expires 1d; //缓存1天
                break;
            }
        }

        location ~ .*\.(js|css)$
        {
            root /root/static/qsz/public;

        }

        location /management/ {
            # 把 /management 路径下的请求转发给真正的后端服务器
            proxy_pass http://127.0.0.1:8089/management/;
            proxy_cookie_path  /management/ /;
            proxy_set_header   Host    $host;
            proxy_set_header Cookie $http_cookie;
            proxy_set_header   Remote_Addr    $remote_addr;
            proxy_set_header   X-Real-IP    $remote_addr;
            proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;

            client_max_body_size 200m;

            proxy_connect_timeout 18000;

            proxy_send_timeout 18000;

            proxy_read_timeout 18000;
        }
    }

    

    
}