Skip to content


HAProxy is free, open source software that provides a high availability load balancer and proxy server for TCP and HTTP-based applications that spreads requests across multiple servers. It is written in C and has a reputation for being fast and efficient (in terms of processor and memory usage).

Use HAProxy as a reverse proxy

reverse proxy is a type of proxy server that retrieves resources on behalf of a client from one or more servers. These resources are then returned to the client, appearing as if they originated from the server itself. Unlike a forward proxy, which is an intermediary for its associated clients to contact any server, a reverse proxy is an intermediary for its associated servers to be contacted by any client. In other words, a proxy is associated with the client(s), while a reverse proxy is associated with the server(s); a reverse proxy is usually an internal-facing proxy used as a 'front-end' to control and protect access to a server on a private network.

It can be done at Web server level (Nginx, Apache, ...) or at load balancer level.

This HAProxy post shows how to translate Apache's proxy pass directives to the HAProxy configuration.

    frontend ft_global
     acl    req.hdr(Host)
     acl path_mirror_foo path -m beg   /mirror/foo/
     use_backend bk_myapp if path_mirror_foo
    backend bk_myapp
    # external URL                  => internal URL
    # =>
     # ProxyPass /mirror/foo/
     http-request set-header Host
     reqirep  ^([^ :]*)\ /mirror/foo/(.*)     \1\ /\2
     # ProxyPassReverse /mirror/foo/
     # Note: we turn the urls into absolute in the mean time
     acl hdr_location res.hdr(Location) -m found
     rspirep ^Location:\ (https?://[0-9]+)?)?(/.*) Location:\ /mirror/foo3 if hdr_location
     # ProxyPassReverseCookieDomain
     acl hdr_set_cookie_dom res.hdr(Set-cookie) -m sub Domain=
     rspirep ^(Set-Cookie:.*)\*) \1\\2 if hdr_set_cookie_dom
     # ProxyPassReverseCookieDomain / /mirror/foo/
     acl hdr_set_cookie_path res.hdr(Set-cookie) -m sub Path=
     rspirep ^(Set-Cookie:.*)\ Path=(.*) \1\ Path=/mirror/foo2 if hdr_set_cookie_path

Other useful examples can be retrieved from drmalex07 or ferdinandosimonetti gists.


Last update: 2021-04-08