Skip to content

Instantly share code, notes, and snippets.

@james-huston
Created December 23, 2014 18:03
Show Gist options
  • Save james-huston/f2a9b15aacb417d33bd2 to your computer and use it in GitHub Desktop.
Save james-huston/f2a9b15aacb417d33bd2 to your computer and use it in GitHub Desktop.
haproxy.conf polling and sockets with sticky sessions using url param
global
maxconn 32768
quiet
# Performance turning
tune.maxaccept -1
stats socket /tmp/haproxy.sock mode 0666 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
hash-type consistent wt6
option httpchk GET /status-check
http-check expect string ok
listen stats *:1936
stats enable
stats uri /
stats hide-version
stats auth no:goaway
frontend public
maxconn 6000
# HTTPS
bind *:443 ssl crt /home/ec2-user/etc/wildcard.articulate.io.pem
# HTTP
bind *:4000
# 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_beg(host) -i live
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 app01 app01.articulate.io:8000 maxconn 2000 check
server app02 app02.articulate.io:8000 maxconn 2000 check
server app03 app03.articulate.io:8000 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 app01 app01.articulate.io:8000 maxconn 2000 check
server app02 app02.articulate.io:8000 maxconn 2000 check
server app03 app03.articulate.io:8000 maxconn 2000 check
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment