Skip to content

Instantly share code, notes, and snippets.

@xinz
Created July 9, 2012 10:39
Show Gist options
  • Save xinz/3075716 to your computer and use it in GitHub Desktop.
Save xinz/3075716 to your computer and use it in GitHub Desktop.
a simple HAProxy configure for the websocket
global
log 127.0.0.1 local0 info
maxconn 5000
ulimit-n 10000
defaults
log global
mode http
frontend pub-srv 0.0.0.0:8080
maxconn 5000
timeout client 40s
use_backend websocket if { hdr(Upgrade) -i WebSocket }
default_backend http
backend websocket
timeout connect 100s
timeout server 600s
server ws1 localhost:8084 weight 1 maxconn 2500 check
server ws2 localhost:8085 weight 1 maxconn 2500 check
backend http
timeout connect 40s
timeout server 30s
server www1 localhost:8084 weight 1 maxconn 2500 check
server www2 localhost:8085 weight 1 maxconn 2500 check
@xinz
Copy link
Author

xinz commented Jul 9, 2012

Note:
0. Ensure you have successfully installed the HAProxy (I'm testing with haproxy-1.4.21), and then execute "haproxy -f {correct_path_for_this_conf}/haproxy.conf"

  1. The port:8080 is the public proxy port for the backend 8084 and 8085 web app instances.
  2. HAProxy doesn't enable log as default, you can remove "log 127.0.0.1 local0 info" firstly, and for log configs, the following links may be helpful:
    http://linuxadminzone.com/enable-or-fix-logging-for-haproxy-load-balancer/
    http://kevin.vanzonneveld.net/techblog/article/haproxy_logging/
    http://code.google.com/p/haproxy-docs/wiki/Logging#Examples_of_logs
  3. The above config is a simple testing, please config refer more for your actual webapp.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment