2017-05-03 37 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