Skip to content

Instantly share code, notes, and snippets.

@markwylde
Created December 16, 2016 15:30
Show Gist options
  • Save markwylde/a26fa92044216a32aaa1cfd839253848 to your computer and use it in GitHub Desktop.
Save markwylde/a26fa92044216a32aaa1cfd839253848 to your computer and use it in GitHub Desktop.
Setup haproxy to proxy two apps by path
global
maxconn 4096
user haproxy
group haproxy
daemon
node lb1
spread-checks 5
defaults
log global
mode http
option dontlognull
retries 3
option redispatch
maxconn 2000
contimeout 5000
clitimeout 50000
srvtimeout 50000
frontend web
bind :80
mode http
acl want_app1 path_dir app1
acl want_app2 path_dir app2
use_backend app1 if want_app1
use_backend app2 if want_app2
backend app1
mode http
option httpclose
reqirep ^([^\ ]*)\ /app1/([^\ ]*)\ (.*)$ \1\ /\2\ \3
rspirep ^(Location:)\ http://([^/]*)/(.*)$ \1\ http://\2/app1/\3
option httpchk GET / HTTP/1.0\r\nUser-Agent:\ HAProxy
server app1_1 0.0.0.0:81
# the following backends follow the same pattern
backend app2
mode http
option httpclose
reqirep ^([^\ ]*)\ /app2/([^\ ]*)\ (.*)$ \1\ /\2\ \3
rspirep ^(Location:)\ http://([^/]*)/(.*)$ \1\ http://\2/app2/\3
option httpchk GET / HTTP/1.0\r\nUser-Agent:\ HAProxy
server app2_1 0.0.0.0:82
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment