问题
I have tried every conceivable haproxy configuration posted in blogs and stackoverflow, but I still cannot get haproxy and socket.io to work 100% of the time. In the majority of browsers that "support" web sockets it fails and falls back on long polling after missed heart beats. The browser appears to make the initial connection (nodejs debugging), but I cannot get the clients to receive the connection response. Is anyone else having similar problems? Below are the software version numbers and a couple of the configs I have tried.
- haproxy 1.4.18
- node 0.6.5
- socket.io 0.8.7
Haproxy configurations (I have tried many more and numerous options):
- http://engineering.bistri.com/post/14307969768/socket-io-haproxy-http-authentication
- HAProxy + WebSocket Disconnection
- http://pastebin.com/H3XNv0TQ
- http://www.darkcoding.net/software/proxy-socket-io-and-nginx-on-the-same-port-over-ssl/ (minus ssl stuff)
Web sockets working in:
- Safari 5 (Windows)
- Chrome 11 (Linux)
回答1:
Websockets cannot be reverse proxy'd because the 8 bytes of data the client must send after the headers is not advertised in a Content-Length header, so the intermediates won't forward that data until the handshake completes. And since the handshake needs those 8 bytes to complete, the handshake never completes and deadlocks, http://www.enotes.com/topic/WebSockets#Proxy_traversal. This is not the only source. Many more sources verify that they cannot be reverse proxy'd.
来源:https://stackoverflow.com/questions/8662377/haproxy-and-socket-io-not-fully-working