HAProxy rewrite of host and path
Asked Answered
B

2

5

this should be a pretty simple rewrite rule, but I can't get it working. I want to rewrite Request as follows:

http://acme.org/FOO/BAR

to

http://FOO.acme.org/BAR

FOO is some simple string in this case and BAR should match the rest of the URL. It seems as reqrep does not allow the rewrite of the host :(

Burgoo answered 5/3, 2014 at 16:27 Comment(0)
S
8

But nowadays it's better to replace host with

http-request replace-header Host .* FOO.acme.org

since reqirep is deprecated since haproxy 1.6.

Shericesheridan answered 7/10, 2019 at 8:40 Comment(4)
Thank you for updating this, reqirep seems not to be deprecated in 1.6, but now sure is: cbonte.github.io/haproxy-dconv/2.0/configuration.html#4-reqirepBurgoo
"Using "reqadd"/"reqdel"/"reqrep" to manipulate request headers is discouraged in newer versions (>= 1.5)."Shericesheridan
If you want to replace .*, then just use http-request set-header Host FOO.acme.orgDicrotic
@rustyx: nope. Not working for me with HAProxy 1.7.9. It keeps requesting my default backend, ends up in a 404, and tells my browser that the other server answered that... but that's not right, it's just a masquerade of Host.Lethalethal
P
6

You can rewrite the host with reqrep, try this:

acl match path_end -i /FOO/BAR
reqirep ^Host: Host:\ FOO.acme.org if match
Predator answered 7/3, 2014 at 18:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.