Skip to content

Instantly share code, notes, and snippets.

@yodiaditya
Created September 21, 2011 11:05
Show Gist options
  • Save yodiaditya/1231808 to your computer and use it in GitHub Desktop.
Save yodiaditya/1231808 to your computer and use it in GitHub Desktop.
Haproxy.cfg on EC2 which NGINX run on port 81, NodeJS on port 8003.
#
# dvv's way to configure haproxy
# Modified by yodiaditya
global
maxconn 32768 # concurrent connections limit
user nobody
spread-checks 5
defaults
mode http
option abortonclose
no option accept-invalid-http-request
no option accept-invalid-http-response
option allbackups
option forwardfor except 127.0.0.1 header X-Forwarded-For
option redispatch
retries 3
option tcp-smart-connect
frontend all 0.0.0.0:80
# proxy HTTP
default_backend nginx
# proxy true WebSockets and socket.io fallbacks
acl is_websocket hdr(upgrade) -i websocket
acl is_websocket hdr_beg(host) -i ws
acl is_websocket hdr_end(host) -i chat.obrool.com
# N.B. the best is to place socket.io.min.js under production static server
# so that it won't interfere here
acl is_websocket path_beg /socket.io/
use_backend websockets if is_websocket
# TODO: how to vary depending on backend?
#
# client must send the data within 25 seconds. should equal server timeout
# TODO: long upload? route to another server?
timeout client 1d #25s
#nginx
backend nginx
balance roundrobin
option forwardfor # This sets X-Forwarded-For
server nginx 127.0.0.1:81 weight 1 maxconn 1024 check
# timeouts
option forceclose
# server must be contacted within 5 seconds
timeout connect 5s
# all headers must arrive within 3 seconds
timeout http-request 3s
# server must respond within 25 seconds. should equal client timeout
timeout server 25s
#
# don't close connection for 1 ms
# helps to glue several short requests in one session
# N.B. >10 can dramatically slow down short requests
#
timeout http-keep-alive 1
backend websockets
# workers
default-server weight 50 maxqueue 16384 maxconn 16384 slowstart 1000 inter 5000 fastinter 500 downinter 10000 rise 2 fall 3
#
# CONFIG: enlist workers.
# you should copy the list from above section
#
server s1 127.0.0.1:8003
# balance the load
balance roundrobin
# cookie persistence
cookie SERVERID insert indirect nocache
# timeouts
#option forceclose
timeout queue 5s
# support long-polling: socket.io uses circa 20-25 second requests, lets double the time
timeout connect 60s
timeout server 60s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment