Redirect HAproxy:在后端重定向到https

Redirect HAproxy:在后端重定向到https,redirect,haproxy,Redirect,Haproxy,我的工作场所有一个HAproxy,我们使用它来路由到只需要一个公共IP的Web服务器。我们的一些客户想要https,而有些客户不想要 我想强制每个后端的基础上https 我发现了这个,只是它没有说这个配置是用于前端还是后端。也许两者都能用 http请求重定向位置[代码][] 或者这个: 模式http 重定向方案https如果!{ssl_fc} 所以我想我把这个放在一些后端: http请求重定向位置[代码301] 这样行吗?我们的实验室环境。已被占用,因此我无法及时对其进行测试。我创建了自己的测试

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

我想强制每个后端的基础上https

我发现了这个,只是它没有说这个配置是用于前端还是后端。也许两者都能用

http请求重定向位置[代码][]

或者这个:

模式http

重定向方案https如果!{ssl_fc}

所以我想我把这个放在一些后端:

http请求重定向位置[代码301]


这样行吗?我们的实验室环境。已被占用,因此我无法及时对其进行测试。

我创建了自己的测试后端。。 这项工作:

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

因此,这将起作用(从工作部署复制)

因为
!{ssl_fc}
check本质上只是另一个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

把这些放在前端。当你重定向时,几乎没有理由让请求继续到选择后端的位置。我通常避免使用301重定向,因为无法保证用户是否/何时访问重定向的URL。从另一个答案来看:
backend https_for_all_traffic
    redirect scheme https if !{ ssl_fc }

    server https_only 10.21.5.73:80
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