Skip to content

Instantly share code, notes, and snippets.

Last active February 7, 2023 14:55
  • Star 34 You must be signed in to star a gist
  • Fork 9 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Perform simple reverse-proxying in HAProxy. #reverse-proxy #proxy #haproxy #proxypass

A more complete example (with rewriting cookie domains/paths) can be found at

We will try something roughly equivalent to the following ProxyPass directives in Apache2:

ProxyPass        /foo/  http://foo.local
ProxyPassReverse /foo/  http://foo.local

In haproxy.cfg we define a backend, say foo, to reverse-proxy to foo.local backend server.

frontend http-in
    acl prefixed-with-foo  path_beg /foo/
    acl host-is-www-example    hdr(host) eq
    use_backend foo-backend if  host-is-www-example prefixed-with-foo
    # other rules ...
    default_backend default-backend

backend foo-backend
    http-request set-header Host foo.local
    server node1 foo.local:80
    # Map url path as ProxyPass does
    reqirep  ^(GET|POST|HEAD)\ /foo/(.*)     \1\ /\2
    # Rewrite redirects as ProxyPassReverse does
    acl response-is-redirect res.hdr(Location) -m found
    rspirep ^Location:\ (http|https)://foo.local\/(.*)   Location:\ \1://\2  if response-is-redirect
    #option forwardfor
Copy link

This works perfectly! Full champion. For help with HTTPS go here:

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