替换 HAProxy 2.2.25 中的 reqirep 指令

问题描述 投票:0回答:1

我已经从旧版本的 HAProxy 升级到 2.2.25。 在配置文件中我有这一行:

reqirep Destination:\ https(.*) Destination:\ http\\1

2.2.25,我得到这个错误:

Errors found while starting haproxy
[NOTICE] 064/171311 (1035) : haproxy version is 2.2.25-50b5f5d
[ALERT] 064/171311 (1035) : parsing [/var/etc/haproxy_test/haproxy.cfg:102] : The 'reqirep' directive is not supported anymore since HAProxy 2.1. Use 'http-request replace-header' instead.
[ALERT] 064/171311 (1035) : Error(s) found in configuration file : /var/etc/haproxy_test/haproxy.cfg
[ALERT] 064/171311 (1035) : Fatal errors found in configuration. 

2.2.25 中的新语法是什么?

我看过

http-request replace-header
但它不起作用:-(

haproxy
1个回答
0
投票

等效配置为

http-request replace-header Destination (?i)https(.*) http\1

有关http-request replace-header规则的完整文档,请参阅

https://docs.haproxy.org/2.2/configuration.html#http-request%20replace-header

请注意,所有

http-request
规则都是按照它们在配置文件中声明的严格顺序进行评估的。此顺序可能不同于之前使用
req*
规则评估规则的顺序。

另请注意,在搜索正则表达式中,我使用了内联修饰符来打开不区分大小写的匹配。这使得查询等同于您的

reqirep
规则,该规则也使用不区分大小写的匹配。默认情况下,
http-request replace-header
匹配区分大小写(即等同于
reqrep
)。

最后,原始配置中

\\1
中的双反斜杠很奇怪。我认为这是您引用和/或模板语言的产物。当使用您的实际原始语句时,您的
Destination
标头将替换为文字
http\1
值,而不是插入正则表达式中匹配的标头值的其余部分。

© www.soinside.com 2019 - 2024. All rights reserved.