Socket.IO cluster with nginx load balancing issues

I am running NGINX as a reverse proxy for the Socket.IO server, which loads balance requests across multiple cluster processes. Each of the cluster processes is invited to listen on different ports.

The nginx server is configured to load balance based on the IP hash, but I get the message:

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

In my nginx configuration there is:

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

default 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; } } 

Any help would be greatly appreciated. If I started the nodejs server without a cluster, it behaves correctly, the link that I used for this setting is found at: http://socket.io/docs/using-multiple-nodes/ .

thanks

+5
source share
1 answer

I found that the problem is that the installed version of nginx was <1.3 and did not support websockets.

For anyone else, you can check how to install a newer version of nginx on ubuntu:

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

0
source

Source: https://habr.com/ru/post/1205300/


All Articles