Rewrite request URI based on Host header in HAProxy

Posted by DorinC on Server Fault See other posts from Server Fault or by DorinC
Published on 2011-03-18T05:57:51Z Indexed on 2011/03/18 8:11 UTC
Read the original article Hit count: 398

Filed under:
|

I would like to set up HAProxy to forward HTTP requests to some backend servers but I need it to also rewrite the URI part based on the Host. I've read through the doc but it seems that reqirep isn't suitable for this purpose. Any idea if this is even possible with HAProxy?

Here are the details of what I'm trying to accomplish:

Requests that come in on:

http://www.original-domain.com/

would be balanced between:

http://server1/domains/www.original-domain.com/
...
http://serverN/domains/www.original-domain.com/

The proxy should be able to handle this for any number of domains (original-domain.com can be anything, it's not limited to a fixed set of values).

For this to work HAProxy would need to rewrite a request like this:

GET /original-uri HTTP/1.1
Host: original-domain.com

to:

GET /domains/original-domain.com/original-uri HTTP/1.1
Host: serverN

and forward that request to one of the internal servers.

© Server Fault or respective owner

Related posts about haproxy

Related posts about rewrite