如果 haproxy 收到来自后端服务器的 404 响应,我会尝试让 haproxy 重定向到新位置。如果它没有收到 404,我希望它能够正常响应。
这对我来说很有意义,但似乎不起作用:
frontend front
option httplog
bind *:8080
default_backend app
backend app
balance roundrobin
acl document_request path_beg -i /documents
acl not_there status 404
http-request redirect location http://newlocation/%[path] if document_request not_there
server webserver1 10.10.10.10:8080 check
我收到以下警告:
acl“not_there”永远不会匹配,因为它只涉及与“后端http请求 header 规则”不兼容的关键字
我在 Centos 7 上使用版本 1.5.14。
关于如何实现这项工作有什么想法吗?可以做我想做的事吗?
任何帮助将不胜感激。
谢谢
AL
最佳答案
http-request redirect
根据检查请求的条件重定向请求(可选)。
status
只能检查响应。 “与 http-request header 规则不兼容”表示 status
仅与 http-response 规则兼容。
当您获得状态代码时,您只能重写其响应。
尝试使用 http-response set-header
分别编辑位置和状态。 设置状态
。
从版本 1.6 开始,您可以使用 http-response 重定向
。
关于load-balancing - haproxy 基于响应状态码重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38833822/