Haproxy reverse proxy and virtual host

haproxyreverse-proxy

I'm trying to configure haproxy (1.5.8) in reverse proxy mode linking to some kind of virtualhost hosted on an old Unix server. The haproxy will be in DMZ and the webserver on the LAN.

Basically I want:

https://a.domain.com/lo -> http://a.b.c.d:5000/lo
https://a.domain.com/lp -> http://a.b.c.d:5500/lp

By defaut the Unix server will throw a virtualhost error if i try to connect to http://a.b.c.d:5000/, and will display the webpage if I open http://a.b.c.d:5000/lo.

frontend ft1
        mode http
        option forwardfor
        bind *:443 ssl crt /etc/ssl/certs.pem
        use_backend bk_Lo if { path_beg /lo }
        use_backend bk_Lp if { path_beg /lp }
        default_backend bk_Lo

backend bk_Lo
        mode http
        server lo a.b.c.d:5000

backend bk_Lp
        mode http
        server lp a.b.c.d:5500

But I can't figure a way to rewrite the url correctly, I always end up with an error 503.
Is this even possible with haproxy ?
Can someone point me in the right direction to solve this?

Thank you for your help.

Davron

Best Answer

you need to add this to your backend section:

http-request set-header Host a.b.c.d

frontend ft1
        mode http
        option forwardfor
        bind *:443 ssl crt /etc/ssl/certs.pem
        use_backend bk_Lo if { path_beg /lo }
        use_backend bk_Lp if { path_beg /lp }
        default_backend bk_Lo

backend bk_Lo
        mode http
        server lo a.b.c.d:5000
 **http-request set-header Host a.b.c.d**

backend bk_Lp
        mode http
        server lp a.b.c.d:5500
 **http-request set-header Host a.b.c.d**