casualjim
11/7/2011 - 9:08 PM

haproxy.cfg

# /etc/haproxy/haproxy.cfg, version 1.5

global
   maxconn 4096
   #user haproxy
   #group haproxy
   #daemon

defaults
   
  mode http
  option abortonclose
  no option accept-invalid-http-request
  no option accept-invalid-http-response
  option allbackups
  option dontlognull
  option forwardfor except 127.0.0.1 header X-Forwarded-For
  log global
  option httplog
  option log-separate-errors
  option redispatch
  option httpchk GET /1/eb_ping
  # important, see comment from Willy Tarreau bellow
  option http-server-close
  retries 3
  #?option splice-auto
  option tcp-smart-connect

  # backend defaults
  default-server weight 50 maxqueue 16384 minconn 512 maxconn 16384 slowstart 1000 inter 5000 fastinter 500 downinter 10000 rise 2 fall 3
  balance leastconn
  fullconn 10000

  timeout client 60s
  timeout connect 5s
  timeout server 60s

# this load balancer servers both www.site.com and static.site.com, but those two URLS have  
# different servers on the backend (app servers versus statis media apache instances)  
# also, I want to server www.site.com/static/* from the later farm  

frontend http

  bind 0.0.0.0:80

  reqadd X-Forwarded-Proto:\ http

  # NAT static host names and static paths in other hostnames to static.bullhornreach.com
  acl is_stream hdr_beg(host) -i stream
  acl is_websocket hdr(Upgrade) -i WebSocket
  use_backend stream if is_stream
  use_backend websocket if is_websocket

   
  default_backend www

frontend https

  bind 127.0.0.1:10180 accept-proxy
  reqadd X-Forwarded-Proto:\ https

   # NAT static host names and static paths in other hostnames to static.bullhornreach.com
  acl is_stream hdr_beg(host) -i stream
  acl is_websocket hdr(Upgrade) -i WebSocket
  use_backend stream if is_stream
  use_backend websocket if is_websocket
   
  default_backend www

backend www
  server www1 127.0.0.1:12180 check port 12180
  #server www2 www2 check port 80
  #server www3 www3 check port 80
  # provide a maintenance page functionality, only used when all other servers are down
  #server load1 localhost:8080 backup


backend stream
  # for static media, connections are cheap, plus the client is very likely to request multiple files  
  # so, keep the connection open (KeepAlive is the default)  
  server streamingserver 127.0.0.1:12188 
  #server media2 media2 check port 80

backend websocket
  
  http-check disable-on-404
  server websocketserver 127.0.0.1:12188 weight 1 maxconn 1024 #check port 12188
  #server s2 $WORKER_2 check cookie s2
  #server s3 $WORKER_3 check cookie s3
  #server s4 $WORKER_4 check backup
  cookie SERVERID insert indirect nocache
  ## uncomment for SockJS
  #balance uri depth 2

  #rate-limit sessions 10

  no option forceclose
  timeout queue 5s
  timeout http-request 5s
  

listen stats :2936
   stats enable
   stats scope http
   stats scope https
   stats scope www
   stats scope stream
   stats scope websocket
   stats scope static_httpclose
   stats realm Haproxy\ Statistics
   stats uri /
   stats auth user:password