Nginx有多层proxy_pass减速?

时间:2016-09-26 02:21:27

标签: nginx

我正在使用单个nginx.exe设置来执行多个proxy_pass,但它似乎导致实际服务器接收消息的延迟。这就是我的意思:Nginx Load Balancer - >上游到Nginx主服务器上游到 - >子服务器。如果需要扩展,我计划多个主服务器。当我测试它时,消息通过,但我必须等待一下。至少1分钟。我不确定我需要在配置文件中更改哪些设置才能使其更加即时。我尝试使用它自己的配置文件运行不同的Nginx.exe实例,但它仍然会导致相同的延迟。所有这些都在一台机器上进行测试。 tcp和http代理都会导致速度减慢。

我的配置文件:

#user  nobody;
worker_processes  1;

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

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}

stream {
    #loginServerLoadBalancer
    server {
        listen 3000;
        proxy_pass loginServerMaster;
    }

    #loginServerMasters
    upstream loginServerMaster {
        server localhost:3100;
    }

    #loginServerMaster
    server {
        listen 3100;
        proxy_pass loginServerChild;
    }

    #loginServerChilds
    upstream loginServerChild {
        server localhost:3101;
        server localhost:3102;
        server localhost:3103;
        server localhost:3104;
        server localhost:3105;
        server localhost:3106;
        server localhost:3107;
        server localhost:3108;
    }

    #matchmakingServerLoadBalancer
    server {
        listen 3400;
        proxy_pass matchmakingServerMaster;
    }

    #matchmakingServerMasters
    upstream matchmakingServerMaster {
        server localhost:3500;
    }

    #matchmakingServerMaster
    server {
        listen 3500;
        proxy_pass matchmakingServerChild;
    }

    #matchmakingServerChilds
    upstream matchmakingServerChild {
        server localhost:3501;
        server localhost:3502;
        server localhost:3503;
        server localhost:3504;
        server localhost:3505;
        server localhost:3506;
        server localhost:3507;
        server localhost:3508;
    }

    #gameServerLoadBalancer
    server {
        listen 3600;
        proxy_pass gameServerMaster;
    }

    #gameServerMasters
    upstream gameServerMaster {
        server localhost:3700;
    }

    #gameServerMaster
    server {
        listen 3700;
        proxy_pass gameServerChild;
    }

    #gameServerChilds
    upstream gameServerChild {
        server localhost:3701;
        server localhost:3702;
        server localhost:3703;
        server localhost:3704;
        server localhost:3705;
        server localhost:3706;
        server localhost:3707;
        server localhost:3708;
    }
}

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

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

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    #loginServerLoadBalancer
    server {
        listen       3050;
        server_name  localhost;
        location / {
            proxy_pass http://loginServerMaster;
        }
    }

    #loginServerMasters
    upstream loginServerMaster {
        server localhost:3150;
    }

    #loginServerMaster
    server {
        listen       3150;
        server_name  localhost;
        location / {
            proxy_pass http://loginServerChild;
        }
    }

    #loginServerChilds
    upstream loginServerChild {
        server localhost:3151;
        server localhost:3152;
        server localhost:3153;
        server localhost:3154;
        server localhost:3155;
        server localhost:3156;
        server localhost:3157;
        server localhost:3158;
    }

    #dataServerLoadBalancer
    server {
        listen       3200;
        server_name  localhost;
        location / {
            proxy_pass http://dataServerMaster;
        }
    }

    #dataServerMasters
    upstream dataServerMaster {
        server localhost:3300;
    }

    #dataServerMaster
    server {
        listen       3300;
        server_name  localhost;
        location / {
            proxy_pass http://dataServerChild;
        }
    }

    #dataServerChilds
    upstream dataServerChild {
        server localhost:3301;
        server localhost:3302;
        server localhost:3303;
        server localhost:3304;
        server localhost:3305;
        server localhost:3306;
        server localhost:3307;
        server localhost:3308;
    }

    #regular server
    server {
        listen       80;
        server_name  localhost;

        #login server load balance via child process
        #location /oauth2 {
        #   proxy_pass http://oauth2;
        #}
        #location /data {
        #   proxy_pass http://data;
        #}

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   /cloud/www;
            index  index.php index.html index.htm;
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        location ~ \.php$ {
            root           /cloud/www;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

}

0 个答案:

没有答案