使用HAproxy将标头添加到特定URL的响应中

Xeo*_*eos 8 load-balancing haproxy

我的HAproxy配置中有一个简单的条件(我试过这个用于前端后端):

acl no_index_url path_end .pdf .doc .xls .docx .xlsx
rspadd X-Robots-Tag:\ noindex if no_index_url
Run Code Online (Sandbox Code Playgroud)

它应该将no-robots标头添加到不应编入索引的内容中.但是WARNING在解析配置时它给了我这个:

acl 'no_index_url' will never match because it only involves keywords
    that are incompatible with 'backend http-response header rule'
Run Code Online (Sandbox Code Playgroud)

acl 'no_index_url' will never match because it only involves keywords
    that are incompatible with 'frontend http-response header rule'
Run Code Online (Sandbox Code Playgroud)

根据文档,rspadd可以在前端后端使用.的path_end是在中实施例中使用的前端.为什么我会收到此错误,这是什么意思?

小智 13

从HaProxy 1.6开始,您将无法忽略错误消息.要使其正常工作,请使用临时变量功能:

frontend main
   http-request set-var(txn.path) path

backend local
   http-response set-header X-Robots-Tag noindex if { var(txn.path) -m end .pdf .doc }
Run Code Online (Sandbox Code Playgroud)