Last active
January 26, 2016 21:07
-
-
Save james-huston/69bbdc352c95a2b05b7e to your computer and use it in GitHub Desktop.
Basic HAProxy config that supports Engine.io 1.x and Socket.io 1.x using both polling and websockets and sticky sessions based on session cookie.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
global | |
maxconn 32768 | |
quiet | |
# Performance turning | |
tune.maxaccept -1 | |
stats socket /tmp/haproxy.sock mode 0600 level admin | |
log 127.0.0.1 local0 notice | |
log 127.0.0.1 local0 debug | |
daemon | |
defaults | |
mode http | |
log global | |
option httplog | |
option dontlognull | |
# Add x-forwarded-for header. | |
option forwardfor | |
option redispatch | |
timeout connect 5s | |
timeout client 30s | |
timeout server 30s | |
# Long timeout for WebSocket connections. | |
timeout tunnel 2h | |
#cookie AIOSERVERID insert indirect nocache | |
balance url_param key | |
option httpchk GET /status-check | |
http-check expect string ok | |
listen stats *:1936 | |
stats enable | |
stats uri / | |
stats hide-version | |
stats auth someuser:password | |
frontend public | |
# HTTPS | |
bind *:443 ssl crt /home/ec2-user/etc/wildcard.articulate.io.pem | |
# HTTP | |
bind *:4000 | |
maxconn 6000 | |
# At most 10 concurrent connections from a client | |
acl too_fast fe_sess_rate ge 10 | |
# Matches any path beginning with a given prefix | |
#acl bursts_inclined path_beg -i / | |
# Effectively working as a delay mechanism for clients that are too fast | |
tcp-request inspect-delay 1000ms | |
# Fast-path - accept connection if it's not this troublesome client | |
#tcp-request content accept unless bursts_inclined too_fast | |
tcp-request content accept unless too_fast | |
# The very fast client gets here meaning they have to wait full inspect-delay | |
tcp-request content accept if WAIT_END | |
acl is_websocket hdr(Upgrade) -i WebSocket | |
# default to the websocket backend | |
default_backend polling | |
use_backend websocket if is_websocket | |
backend polling | |
timeout server 30s | |
option forwardfor | |
server test01 test.articulate.io:8000 maxconn 2000 check | |
server test02 test.articulate.io:7900 maxconn 2000 check | |
backend websocket | |
timeout queue 5000 | |
timeout server 86400000 | |
timeout connect 86400000 | |
timeout check 1s | |
option forwardfor | |
# Do not use httpclose (= client and server | |
# connections get closed), since it will close | |
# Websockets connections | |
no option httpclose | |
# Use "option http-server-close" to preserve | |
# client persistent connections while handling | |
# every incoming request individually, dispatching | |
# them one after another to servers, in HTTP close mode | |
option http-server-close | |
option forceclose | |
server test01 test.articulate.io:8000 maxconn 2000 check | |
server test02 test.articulate.io:7900 maxconn 2000 check |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
adapted from balancerbattle/haproxy.cfg