2017-03-09 22 views
1

我有一個haproxy集羣,有兩個前端用於http和https以及許多使用domain2backend映射選擇的後端。HAProxy在後端不工作的重定向方案

一些後端只能通過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-代理1.7.3版2017年2月28日

回答

4

很多嘗試和感謝幫助的社區後,在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