HAProxy重写主机和路径

man*_*ana 2 haproxy

这应该是一个非常简单的重写规则,但我不能让它工作.我想重写Request如下:

http://acme.org/FOO/BAR
Run Code Online (Sandbox Code Playgroud)

http://FOO.acme.org/BAR
Run Code Online (Sandbox Code Playgroud)

FOO在这种情况下是一些简单的字符串,BAR应该与URL的其余部分匹配.似乎reqrep不允许重写主机:(

And*_*tov 6

但是现在最好将主机替换为

http-request replace-header Host .* FOO.acme.org
Run Code Online (Sandbox Code Playgroud)

因为 reqirep从 haproxy 1.6开始被弃用

  • 如果你想替换`.*`,那么只需使用`http-request set-header Host FOO.acme.org` (3认同)

Goo*_*ner 5

你可以用reqrep,重写主机,试试这个:

acl match path_end -i /FOO/BAR
reqirep ^Host: Host:\ FOO.acme.org if match
Run Code Online (Sandbox Code Playgroud)