I am trying to loadbalance socket.io requests using HAProxy. The following is my configuration:
defaults
log global
mode http
option httplog
option dontlognull
timeout connect 5000
timeout client 50000
timeout server 50000
frontend all 0.0.0.0:8888
mode http
timeout client 120s
option forwardfor
# Fake connection:close, required in this setup.
option http-server-close
option http-pretend-keepalive
acl is_socketio path_beg /socket.io
use_backend socket-servers if is_socketio
default_backend http-servers
backend http-servers
balance roundrobin
option httpclose
option forwardfor
# Roundrobin switching
server node-1 172.14.2.25:8887 check
server node-2 172.14.2.28:8887 check
backend socket-servers
mode http
timeout server 120s
balance roundrobin
# based on cookie set in header
# haproxy will add the cookies for us
option forwardfor
cookie SERVERID insert indirect nocache
server node1 172.14.2.25:8887 cookie node1 weight 1 maxconn 1024 check
server node2 172.14.2.28:8887 cookie node2 weight 1 maxconn 1024 check
This configuration gives timeout when I try to create socket connection.
However, if I delete either on of the last two lines [server node1 172.14.2.25:8887 cookie node1 weight 1 maxconn 1024 check or server node2 172.14.2.28:8887 cookie node2 weight 1 maxconn 1024 check], the socket connects properly.
I do not understand what is wrong with the configuration. Any help will be highly appreciated.
TIA :)
In the configuration of backend socket-servers, I had to change balance roundrobin to balance source. That worked! :)