Question

I created Load Balancer and my socket.io stoped working

Posted October 14, 2019 1.4k views
NginxNetworkingLoad Balancing

After adding Load Balancer, my NodeJs server is not receiving any socket.io handshakes and got’s rejected automatically. The question i have is, do i need to add some specific http/tcp redirect rule to that Load Balancer in order to receive socket.io calls on droplets?

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
Submit an Answer
3 answers

Hello, @bachinadiradze

May I ask if you’ve opened all the needed ports on the Load Balancer? You can check all the ports you need/use and make sure they’re open on the Load Balancer as well.

I’m having a similar issue with NGINX

Did you solve this? I have thesame problem.

  • Hey i did resolve the issue back then. If i remember correctly it wa both Socket.io and Nginix issue and i added some of the proxy headers which fixed nginx side:

    server {
            listen 80;
            listen [::]:80;
    
            server_name www.yourwebsite.com yourwebsite.com;
    
            location / {
                proxy_pass http://localhost:8080;
                proxy_http_version 1.1;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection "upgrade";
                proxy_set_header Host $host;
            }
    }
    

    And socket side i added:

    // library -> socket.io-client
    
    this._socket = io("/", {
       transports: ['websocket', 'pooling'] // this part
    });
    

    Hope it helps. I would go for socket fix first if it won’t do it then you can try nginx one.

    Good luck :)

    edited by MattIPv4