nginx配置备忘

#nginx的进程数
worker_processes 1;

events {

    #每个进程的最大连接数
    worker_connections 512;

}

http {


    include mime.types;
    default_type application/octet-stream;

    #使其客户端保持长连接
    keepalive_timeout 60s;
    keepalive_requests 500;
    gzip on;
    gzip_types text/plain application/x-javascript text/css application/xml text/javascript application/javascript;


    #禁止使用ip访问,
    #如果之前使用ip访问重定向过
    #需要清除301缓存才能表现出
    #server
    #{
     #   listen 80 default;
      #  return 500;
    #}

    #将所有http 跳转至https
    #server {
        #listen 80;
        #server_name dev.atm.com;

        #这里使用302,方便测试, 正式上线后可使用301永久重定向
        #return 302 https://$host$request_uri;
    #}

    #配置后端服务器-使其能保持长连接.
    upstream  easy_server {
        server 127.0.0.1:8300; 

        #可以配置多个负载均衡
        #server 127.0.0.1:8301;

        #保持长连接的数目
        keepalive 100;

        #保持时间
        keepalive_timeout 10000s;
    }

    #用于调试vue项目
    upstream  vue_dev_server {
        server 127.0.0.1:8080; 
        #server 127.0.0.1:8310; 
        
        #可以配置多个负载均衡
        #server 127.0.0.1:8301;

        #保持长连接的数目
        keepalive 100;

        #保持时间
        keepalive_timeout 3000s;
    }

    server {
        listen 80;
        listen 443 ssl;

        server_name dev.atm.com;

        #证书路径
        ssl_certificate D:/nginx/ssl_crt/dev.atm.com.crt;
        ssl_certificate_key D:/nginx/ssl_crt/dev.atm.com.key;
        
        #主目录
        root E:/easy_cpp/easyApp/output/nginx/root;
        
        #按照扩展名转发,如下easy与ws扩展名转发至
        location ~ .*.(easy|es)$ {
            #proxy_pass http://127.0.0.1:8300;
            
            #为了保持长连接这里要使用上面的后端服务器配置,而不是这个指定ip
            proxy_pass http://easy_server;
            
            proxy_set_header Referer $http_referer;
            proxy_set_header Host $host;
            proxy_set_header remote_addr $remote_addr;
            proxy_set_header Connection $http_connection;
            proxy_http_version 1.1;
        }
        
        location /testpath
        {
            proxy_pass http://easy_server/;

            proxy_set_header Referer $http_referer;
            proxy_set_header Host $host;
            proxy_set_header remote_addr $remote_addr;
            proxy_set_header Connection $http_connection;
            proxy_http_version 1.1;
        }
        
        location ~ .*.(ws)$ {
            #proxy_pass http://127.0.0.1:8300;
            proxy_pass http://easy_server;

            proxy_http_version 1.1;
            proxy_set_header Host $host;
            proxy_set_header remote_addr $remote_addr;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection $http_connection;
        }

        location ~* ^(/console|/sockjs-node/|/__webpack_dev_server__/){
            proxy_pass http://vue_dev_server;

            proxy_http_version 1.1;            
            proxy_set_header Referer $http_referer;
            proxy_set_header Host $host;
            proxy_set_header remote_addr $remote_addr;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection $http_connection;
        }
    }
}

 

BOSS

发表评论

PHP Code Snippets Powered By : XYZScripts.com