Why cant we use websocket on our server setup (nginx, node js, load balancer)? It's always going to xhr-polling

We have a web application setup with Barracuda Load Balancer (3 servers running). We want to implement node js using websocket (socket.io) but its always falling into xhr-polling (which is way too slow) if the request comes through the load balancer.

The following are what we tried to fix this:

  • we already opened port 3000 to our service provider on barracuda load balancer
  • used proxy on the nginx configuration as discussed on other stackoverflow questions.
  • upgraded the nginx version to 1.2.7 up to 1.4.1

what puzzling us is that if we only use one server and does not go to load balancer, it will went OK but if we are going through load balancer, it cannot connect via websocket and always falls back to xhr-polling.

this is what nginx error-log is getting:

*14369 connect() failed (111: Connection refused) while connecting to upstream, client: 121.96.XX.XXX, server: www.example.co.uk, request: "GET /socket.io/ HTTP/1.1", upstream: "http://192.168.XX.XXX:3000/socket.io/", host: "www.example.co.uk"