Reverse Proxy amb HaProxy

Exemple de configuració de reverse proxy amb HaProxy amb diferents servers de destí en base a la URI

frontend http-in
    bind 0.0.0.0:80

#    http-request redirect scheme https drop-query append-slash if { path -m str /web1 }
    http-request redirect scheme http drop-query append-slash if { path -m str /web1 }

#    http-request redirect scheme https drop-query append-slash if { path -m str /web2 }
    http-request redirect scheme http drop-query append-slash if { path -m str /web2 }


    acl prefixed-with-web1  path_beg /web1/
    acl prefixed-with-web2  path_beg /web2/

    use_backend web1-backend if prefixed-with-web1
    use_backend web2-backend if prefixed-with-web2

    default_backend web1-backend

backend web1-backend
    http-request set-header Host web1
    server node1 web1:80
    reqrep ^([^\ ]*\ /)web1[/]?(.*)     \1\2
    acl response-is-redirect res.hdr(Location) -m found
    rspirep ^Location:\ (http|https)://web1\/(.*)   Location:\ \1://web.publica.tld/web1/\2  if response-is-redirect

backend web2-backend
    http-request set-header Host web2
    server node1 web2:8080
    reqrep ^([^\ ]*\ /)web2[/]?(.*)     \1\2
    acl response-is-redirect res.hdr(Location) -m found
    rspirep ^Location:\ (http|https)://web2\/(.*)   Location:\ \1://web.publica.tld/web2/\2  if response-is-redirect