【问题标题】:haproxy redirect based on response status code基于响应状态码的 haproxy 重定向
【发布时间】:2016-08-08 16:03:42
【问题描述】:

如果 haproxy 收到来自后端服务器的 404 响应,我正在尝试让其重定向到新位置。如果它没有收到 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' 永远不会匹配,因为它只涉及与 'backend http-request header rule' 不兼容的关键字

我在 Centos 7 上使用的是 1.5.14 版本。

关于如何完成这项工作的任何想法?有可能做我想做的事吗?

任何帮助将不胜感激。

谢谢,

阿尔

【问题讨论】:

    标签: load-balancing haproxy


    【解决方案1】:

    http-request redirect 根据检查请求的条件重定向请求(可选)。

    status 只能检查响应。 'incompatible with http-request header rule' 表示status 只兼容 http-response 规则。

    在您获得状态码时,您只能重写其响应。 尝试分别使用http-response set-header 编辑位置和状态。 set-status

    从 1.6 版开始,您可以使用http-response redirect

    【讨论】:

      猜你喜欢
      • 2020-06-04
      • 2014-02-12
      • 2012-06-25
      • 2019-04-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-19
      • 2020-11-10
      相关资源
      最近更新 更多