2017-05-03 38 views
1

我的工作场所有一个HAproxy,我们用它来路由到只需要一个公共IP的网络服务器。我们的一些客户希望https有些不要。HAproxy:在后端重定向到https

我想在每个后端的基础上实施https。

我发现这个,只是它没有说如果这个配置是用于前端或后端。也许它适用于两者?

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

或该:

模式HTTP

重定向方案HTTPS如果{ssl_fc}

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

http请求重定向位置https://www.somedomain.com [代码301]

将这项工作?我们的实验室env。被捆绑起来,所以我无法及时测试它。

+0

将这些放在前端。当您重定向时,请求甚至没有理由进入后端被选中的位置。 –

+0

我通常回避使用301重定向,因为无法保证用户是否/何时访问重定向的URL。从另外一个答案:['[P] revention胜于治疗 - 如果您不确定是否要永久取消旧版URL调用,请避免301重定向](http://stackoverflow.com/a/21396547/6510524 ) –

回答

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 
0

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,因此您可以进行检查d甚至可以将它与其他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