Skip to content

Instantly share code, notes, and snippets.

@charyorde
Forked from wiredmax/haproxy.cfg
Created September 26, 2018 16:49
Show Gist options
  • Save charyorde/9c460922d7da5530f3bdc183cb1bad20 to your computer and use it in GitHub Desktop.
Save charyorde/9c460922d7da5530f3bdc183cb1bad20 to your computer and use it in GitHub Desktop.
Sample HA-Proxy configuration for load balancing SockJS running on Node.JS servers.
global
maxconn 10000 # Total Max Connections. This is dependent on ulimit
nbproc 2
defaults
mode http
option redispatch
maxconn 2000
contimeout 5000
clitimeout 50000
srvtimeout 50000
option httpclose
frontend all 0.0.0.0:80
timeout client 86400000
acl is_api hdr_dom(host) -i api
use_backend api_http_backend if is_api
acl is_websocket hdr(Upgrade) -i WebSocket
acl is_websocket hdr_beg(Host) -i ws
use_backend ahd_socket_backend if is_websocket # Filter for Websockets
default_backend ahd_http_backend
backend ahd_http_backend
balance roundrobin
cookie SERVERID insert indirect # Match requests to same machines, if possible
option forwardfor # This sets X-Forwarded-For
timeout server 30000
timeout connect 4000
server aas0 10.0.10.76:3000 weight 1 maxconn 5000 cookie AHDFE0 check
server aas1 10.0.10.77:3000 weight 1 maxconn 5000 cookie AHDFE1 check
server aas2 10.0.10.78:3000 weight 1 maxconn 5000 cookie AHDFE2 check
backend ahd_socket_backend
balance roundrobin
cookie SOCKETID insert indirect # Match socket requests to same machines, if possible
option forwardfor # This sets X-Forwarded-For
no option httpclose # To match the `Connection` header for the websocket protocol rev. 76
option http-server-close
option http-pretend-keepalive
timeout queue 5000
timeout server 86400000
timeout connect 86400000
server aas0 10.0.10.76:9000 weight 1 maxconn 5000 cookie AHDSCKT0 check
server aas1 10.0.10.77:9000 weight 1 maxconn 5000 cookie AHDSCKT1 check
server aas2 10.0.10.78:9000 weight 1 maxconn 5000 cookie AHDSCKT2 check
backend api_http_backend
balance roundrobin
cookie SERVERID insert indirect # Match requests to same machines, if possible
option forwardfor # This sets X-Forwarded-For
timeout server 30000
timeout connect 4000
server aas0 10.0.10.76:3001 weight 1 maxconn 5000 cookie APIFE0 check
server aas1 10.0.10.77:3001 weight 1 maxconn 5000 cookie APIFE1 check
server aas2 10.0.10.78:3001 weight 1 maxconn 5000 cookie APIFE2 check
listen stats :8080
mode http
stats enable
#stats hide-version
stats realm Haproxy\ Statistics
stats uri /
stats auth user:password
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment