Skip to content

Instantly share code, notes, and snippets.

@jmandzik
Created January 1, 2014 15:01
Show Gist options
  • Select an option

  • Save jmandzik/8208634 to your computer and use it in GitHub Desktop.

Select an option

Save jmandzik/8208634 to your computer and use it in GitHub Desktop.
HAProxy
global
log 127.0.0.1 local1 notice
maxconn 4096
user haproxy
group haproxy
daemon
ca-base /etc/ssl/certs
crt-base /etc/ssl/certs
defaults
log global
maxconn 4096
mode http
# Add x-forwarded-for header.
option forwardfor
option http-server-close
timeout connect 5s
timeout client 30s
timeout server 30s
# Long timeout for WebSocket connections.
timeout tunnel 1h
frontend public
# HTTP
bind :80
# Redirect all HTTP traffic to HTTPS
redirect scheme https if !{ ssl_fc }
# HTTPS
# Example with CA certificate bundle
# bind :443 ssl crt cert.pem ca-file bundle.crt
# Example without CA certification bunch
bind :443 ssl crt haproxy.pem
# The node backends - websockets will be managed automatically, given the
# right base paths to send them to the right Node.js backend.
#
# If you wanted to specifically send websocket traffic somewhere different
# you'd use an ACL like { hdr(Upgrade) -i WebSocket }. Looking at path works
# just as well, though - such as { path_beg /socket.io } or similar. Adjust your
# rules to suite your specific setup.
use_backend node if { path_beg /socket/ }
# Everything else to Nginx.
default_backend nginx
backend node
# Tell the backend that this is a secure connection,
# even though it's getting plain HTTP.
reqadd X-Forwarded-Proto:\ https
#balance leastconn
# Check by hitting a page intended for this use.
#option httpchk GET /healthcheck.html
#timeout check 500ms
# Wait 500ms between checks.
server node1 127.0.0.1:3000 check inter 500ms
backend nginx
# Tell the backend that this is a secure connection,
# even though it's getting plain HTTP.
reqadd X-Forwarded-Proto:\ https
#balance leastconn
# Check by hitting a page intended for this use.
#option httpchk GET /healthcheck.html
#timeout check 500ms
# Wait 500ms between checks.
server nginx1 127.0.0.1:8080 check inter 500ms
#server nginx1 127.0.0.1:8081 check inter 500ms
# For displaying HAProxy statistics.
frontend stats
# HTTPS only.
# Example with CA certificate bundle
# bind :1936 ssl crt cert.pem ca-file bundle.crt
# Example without CA certification bunch
bind :1936 ssl crt haproxy.pem
default_backend stats
backend stats
stats enable
stats hide-version
stats realm Haproxy\ Statistics
stats uri /
stats auth admin:password
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment