Skip to content

Instantly share code, notes, and snippets.

@haproxytechblog
Last active September 25, 2020 21:11
Show Gist options
  • Save haproxytechblog/38ef4b7d42f16cfe5c30f28ee3304dce to your computer and use it in GitHub Desktop.
Save haproxytechblog/38ef4b7d42f16cfe5c30f28ee3304dce to your computer and use it in GitHub Desktop.
Sample haproxy.cfg
global
log 127.0.0.1 local2
user haproxy
group haproxy
frontend main
bind *:80
mode http
log global
option httplog
default_backend web
use_backend api if { path_beg -i /api/ }
#-----------------------------------------------------------------
# SSL termination - HAProxy handles the encryption.
# To use it, put your PEM file in /etc/haproxy/certs
# then edit and uncomment the bind line (75)
#-----------------------------------------------------------------
# bind *:443 ssl crt /etc/haproxy/certs/haproxy.pem ssl-min-ver TLSv1.2
# redirect scheme https if !{ ssl_fc }
#---------------------------------------------------------------------
# Enable stats at http://test.local:8404/stats
#---------------------------------------------------------------------
frontend stats
bind *:8404
stats enable
stats uri /stats
#---------------------------------------------------------------------
# round robin balancing between the various backends
#---------------------------------------------------------------------
backend web
server web1 127.0.0.1:10080 check
server web2 127.0.0.1:10081 check
#---------------------------------------------------------------------
# API backend for serving up API content
#---------------------------------------------------------------------
backend api
server api1 127.0.0.1:10082 check
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment