I have an haproxy 1.4 installed and I need to configure a reverse proxy in haproxy.conf that rewrites a URL from www.somedomain.com to www.otherdomain.com/bla/ble. the configuration that I am writing is here:
acl cpol_acl hdr_dom(host) -i www.somedomain.com
use_backend cpol_srv if cpol_acl
backend cpol_srv
balance leastconn
mode http
option httplog
stick on src
stick-table type ip size 10240k expire 60m
reqirep ^([^\ :]*)\ /(.*) \1\ /bla/ble\2
reqirep ^Host:\ www.somedomain.com Host:\ www.otherdomain.com
server cpol_srv www.otherdomain.com check port 80
This is working but the URL in the browser does rewrite to www.otherdomain.com/bla/ble and that’s not what I want. If I remove the line
reqirep ^([^\ :]*)\ /(.*) \1\ /bla/ble\2
I only can forward to the host www.otherdomain.com but the URL in the browser stays with www.somedomain.com.
Is there any way of doing this types of reverse proxy without rewriting the browser URL?
PS: I would do this Apache style (which works) but the machine does not have any NAT to the world outside, and can only communicate to haproxy.
Well, after a while I figured out what has to be done.
It’s not sufficient to change only the request but also have to change the response back to the original requesting host. It was also made an acl to prevent repetition of the directory url part “/bla/ble”. Sticking to the example above this should be done like so: