簡體   English   中英

帶有nginx負載均衡器問題的Socket.IO集群

[英]Socket.IO Cluster with nginx load balancer issues

我正在運行NGINX作為Socket.IO服務器的反向代理,該服務器負載平衡多個集群進程的請求。 每個集群進程都被告知要偵聽不同的端口。

nginx服務器配置為基於IP哈希加載平衡,但我收到消息:

ws://{domain}/socket.io/?EIO=3&transport=websocket&sid=KaU3C8caGVK4gU1LAAAB failed: WebSocket is closed before the connection is established.

我的nginx配置有:

http {
    {+ default configs}

    upstream io_nodes {
        ip_hash;
        server 127.0.0.1:3000;
        server 127.0.0.1:3001;
        server 127.0.0.1:3002;
        server 127.0.0.1:3003;
    }

}

默認vhost:

server {
#listen   80; ## listen for ipv4; this line is default and implied
#listen   [::]:80 default ipv6only=on; ## listen for ipv6

root /usr/share/nginx/www/static/web;
index index.html index.htm;

# Make site accessible from http://localhost/
server_name {domain};

location / {
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $host;
        proxy_http_version 1.1;
        proxy_pass http://io_nodes;
     }
}

任何幫助,將不勝感激。 如果我在沒有集群的情況下運行nodejs服務器,它的行為正確,我在此設置中使用的引用位於: http//socket.io/docs/using-multiple-nodes/

謝謝

我發現問題是安裝的nginx版本<1.3並且沒有支持websockets。

對於其他任何人,您可以查看如何在ubuntu上安裝更新版本的nginx:

http://usefulmix.com/install-upgrade-to-latest-nginx-without-compiling-from-source/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM