Disabling HAProxy + WebSocket

I use HAProxy to send requests on a subdomain to node.js.

I can not get WebSockets to work. So far, I could only force the client to establish a connection to WebSocket, but after that a disconnect occurs, which follows very soon.

I am on ubuntu. I used different versions of socket.io and node-websocket-server . The client is either the latest versions of Safari or Chrome. HAProxy Version - 1.4.8

Here is my HAProxy.cfg

 global maxconn 4096 pidfile /var/run/haproxy.pid daemon defaults mode http maxconn 2000 option http-server-close option http-pretend-keepalive contimeout 5000 clitimeout 50000 srvtimeout 50000 frontend HTTP_PROXY bind *:80 timeout client 86400000 #default server default_backend NGINX_SERVERS #node server acl host_node_sockettest hdr_beg(host) -i mysubdomain.mydomain use_backend NODE_SOCKETTEST_SERVERS if host_node_sockettest backend NGINX_SERVERS server THIS_NGINX_SERVER 127.0.0.1:8081 backend NODE_SOCKETTEST_SERVERS timeout queue 5000 timeout server 86400000 server THIS_NODE_SERVER localhost:8180 maxconn 200 check 

I skipped the list of web pages and mailing lists, but could not get any of the proposed solutions to work.

(ps this might be for serverfault, but there are other HAProxy issues on SO, so I decided to post here)

+43
reverse-proxy websocket haproxy
Dec 05 '10 at 17:45
source share
4 answers

Update to the latest version of socket.io (0.6.8 β†’ npm install socket.io@0.6.8 , which is fixed for working with HAProxy) and download the latest version of HAProxy.

Here is an example configuration file:

 global maxconn 4096 # Total Max Connections. This is dependent on ulimit nbproc 2 defaults mode http frontend all 0.0.0.0:80 timeout client 5000 default_backend www_backend acl is_websocket hdr(Upgrade) -i WebSocket acl is_websocket hdr_beg(Host) -i ws use_backend socket_backend if is_websocket backend www_backend balance roundrobin option forwardfor # This sets X-Forwarded-For timeout server 5000 timeout connect 4000 server server1 localhost:8081 weight 1 maxconn 1024 check server server2 localhost:8082 weight 1 maxconn 1024 check server server3 localhost:8083 weight 1 maxconn 1024 check backend socket_backend balance roundrobin option forwardfor # This sets X-Forwarded-For timeout queue 5000 timeout server 5000 timeout connect 5000 server server1 localhost:8081 weight 1 maxconn 1024 check server server2 localhost:8082 weight 1 maxconn 1024 check server server3 localhost:8083 weight 1 maxconn 1024 check 
+60
Jan 19 '11 at 16:12
source share

Your client is probably using WebSockets version 76. In this case, you cannot use "http mode" because shaking hands with WebSockets violates HTTP. There seems to be ambivalence on the committee as to whether WebSockets handshaking should be HTTP compatible or not. In any case, the problem with the v76 handshake is that the raw data is sent using a handshake (checksum block).

Related HAProxy discussion: http://www.mail-archive.com/haproxy@formilux.org/msg03046.html

From the discussion, it seems that there may be a default way to use TCP mode and return to HTTP for connections other than WebSockets.

+5
Dec 05 '10 at 18:32
source share

We use the Netty implementation https://github.com/ibdknox/socket.io-netty , and here is the HAProxy file that worked for us. The trick is to force it not to return to the XHR poll, but to use Websockets, puts HAProxy in TCP mode. HAProxy Configuration:

 global daemon maxconn 32000 defaults mode http timeout connect 5000ms timeout client 50000ms timeout server 50000ms listen http-in bind *:80 server server1 1.1.1.1:8000 check server server2 1.1.1.1:8000 check listen socketio-in mode tcp bind *:8080 balance source timeout queue 5000 timeout server 86400000 timeout connect 86400000 server server1 1.1.1.1:8080 check server server2 1.1.1.1:8080 check 

Where 1.1.1.1 are your IP addresses

+4
Jun 15 2018-11-11T00:
source share

Try using Socket.io instead of node -websockets-server, this is an abstraction layer with backups for many different methods of instant communication between the browser and the server.

Although true WebSockets violate HTTP 1.0, they do not violate HTTP 1.1, so you can proxy them with any server that can proxy HTTP 1.1

-one
Dec 14 '10 at 17:26
source share



All Articles