【问题标题】:HAProxy redirect scheme in backend not working后端的 HAProxy 重定向方案不起作用
【发布时间】:2017-07-30 16:27:42
【问题描述】:

我有一个 haproxy 集群,它有两个用于 http 和 https 的前端以及许多使用 domain2backend 映射选择的后端。

某些后端只能通过 HTTPS 访问。

我尝试在这些后端使用redirect scheme https code 301 if !{ ssl_fc },但 haproxy 似乎忽略了它。我什至尝试简单地重定向(没有任何条件),但 haproxy 忽略了后端部分的重定向。

配置摘录:

global
    maxconn 1024
    debug
    log localhost local0 debug
    tune.ssl.default-dh-param 2048

defaults
    balance roundrobin
    maxconn 32
    log global
    monitor-uri /haproxy_test
    timeout connect 5000ms
    timeout client 50000ms
    timeout server 50000ms

frontend http-in
    bind *:8080
    mode http
    option httplog
    option forwardfor
    use_backend %[req.hdr(host),lower,map_dom(./etc/domain2backend.map)]

frontend https-in
    bind *:4443 ssl crt ./etc/ssl
    mode http
    option httplog
    option forwardfor
    http-request add-header X-Proto https if { ssl_fc }
    use_backend %[req.hdr(host),lower,map_dom(./etc/domain2backend.map)]

backend app1_www
    redirect scheme https if !{ ssl_fc }
    server localhost:3000 127.0.0.1:3000 check

backend app2_www
    redirect scheme https
    server localhost:3000 127.0.0.1:3000 check

app1_www 和 app2_www 重定向都不起作用。

我正在使用 HA-Proxy 版本 1.7.3 2017/02/28

【问题讨论】:

    标签: redirect haproxy


    【解决方案1】:

    经过多次尝试并感谢http://discourse.haproxy.org 的乐于助人的社区,我找到了解决方案:

    必须在后端指定mode http 以允许重定向工作。

    变量 ssl_fc 在后端可用,因此可以使用条件if !{ ssl_fc},如下面的代码示例:

    backend app1_www
        mode http
        redirect scheme https if !{ ssl_fc }
        server localhost:3000 127.0.0.1:3000 check
    

    【讨论】:

      猜你喜欢
      • 2016-12-07
      • 1970-01-01
      • 2014-12-08
      • 2017-10-01
      • 1970-01-01
      • 2018-07-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多