【问题标题】:HAproxy: Redirect to https in backendHAproxy:在后端重定向到 https
【发布时间】:2017-10-01 05:41:51
【问题描述】:

我的工作场所有一个 HAproxy,我们用它来路由到只需要一个公共 IP 的网络服务器。我们的一些客户需要 https,一些则不需要。

我想针对每个后端强制执行 https。

我找到了这个,只是它没有说明这个配置是用于前端还是后端。也许两者都适用?

http-request 重定向位置 [代码] [] []

或者这个:

模式http

重定向方案 https if !{ ssl_fc }

所以我认为我把它放在了一些后端:

http-request 重定向位置https://www.somedomain.com [code 301]

这行得通吗?我们的实验室环境。被捆绑了,所以我无法及时对其进行测试。

【问题讨论】:

标签: redirect haproxy


【解决方案1】:

我创建了自己的测试后端.. 这有效:

backend lb_customername
          mode http
          redirect scheme https if !{ ssl_fc }

          balance roundrobin

          server server1 10.0.0.51:80 maxconn 200
          server server2 10.0.0.52:80 maxconn 200

【讨论】:

    【解决方案2】:

    来自the HAProxy documentation for redirect scheme

    May be used in sections
    defaults    no
    frontend    yes
    listen      yes
    backend     yes
    

    所以这会起作用(从工作部署中复制)

    backend https_for_all_traffic
        redirect scheme https if !{ ssl_fc }
    
        server https_only 10.21.5.73:80
    

    由于!{ ssl_fc } 检查本质上只是另一个 ACL,您甚至可以将它与其他 ACL 组合并仅转发某些流量:

    backend https_for_some_traffic
        # Detect traffic to admin pages
        acl secure    url_beg    /admin
    
        # Force any HTTP admin traffic to HTTPS
        #  the conditions are combined with an implicit AND
        redirect scheme https if !{ ssl_fc } secure
    
        server both_http_and_https 10.21.5.73:80
    

    【讨论】:

      猜你喜欢
      • 2012-10-25
      • 2020-09-24
      • 1970-01-01
      • 1970-01-01
      • 2014-12-08
      • 2015-08-04
      • 2018-11-26
      • 1970-01-01
      • 2015-12-29
      相关资源
      最近更新 更多