Nginx 配置

nginx.conf文件的http {}部分中,您可以使用要在以下两者之间平衡负载的socket.io进程列表声明upstream部分:

http{
    server{
        listen 3000;
        server_name io.yourhost.com;

        location / {
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header Host $host;

            proxy_pass http://nodes;

            # 启用websockets
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";


            }
        }
        upstream nodes {
            # 基于IP启用粘性会话
            ip_hash;
            server app01:3000;
            server app02:3000;
            server app03:3000;

        }
    }

请注意ip_hash指令,它指示连接将是粘性的。

确保在最顶层配置worker_process,以指示nginx应该使用多少worker。您还可能希望调整events {}块中的worker_connections设置。

例子

results matching ""

    No results matching ""