1.5 版中的新http-response add-header
指令是该指令。正如文档中所写的那样- 这可以用于frontend
,backend
和listen
。
我在一个frontend
部分中尝试做的事情:
use_backend some_backend if some_condition
http-response add-header Vary Origin if some_condition
Run Code Online (Sandbox Code Playgroud)
但这没有效果。放置在该backend
部分中的同一行工作得很好。有人可以帮助我理解,我在这里缺少什么吗?我不明白,为什么这在该frontend
部分不起作用。
My guess would be that within the fronted
there is no response yet and so the directive fails. I tried using it before and after die use_backend
directive.
haproxy -d -V -f haproxy.cfg
使用您的示例在前台 ( ) 中运行 haproxy显示以下警告:
acl 'some_condition' will never match because it only involves keywords that are incompatible with 'frontend http-response header rule'
Run Code Online (Sandbox Code Playgroud)
摆弄我的配置,我发现使用此 ACL 时会显示此警告:
acl some_condition req.hdr(Content-Type) -i application/json
Run Code Online (Sandbox Code Playgroud)
但在使用此 ACL 时则不然:
acl some_condition res.hdr(Content-Type) -i application/json
Run Code Online (Sandbox Code Playgroud)
区别在于res
vs. req
,因此检查响应标头而不是请求标头。这让我相信 a 中的http-response header
规则frontend
无法检查request
标题。
我不知道这是否是 HAProxy 的预期功能,但肯定没有明确记录。