2016-12-31 46 views
1

我是HAProxy的新手。我試圖配置HAProxy將URL轉發到特定的URI。 例如,我的網址是https://www.example.com,我想將它轉發到https://www.example.com/aks/將默認URL轉發到HAProxy中的特定URI

我HAProxy的配置是:

frontend Listen443 
    bind *:443 ssl crt /etc/ssl/certs/example.com-wildcard.pem 

    acl web_url   path_beg /aks 
    use_backend WEB  if web_url 

    default_backend WEB 

# Send traffic to the web layer on port 8080 

backend WEB 


    mode http 

    balance roundrobin 

    option httpclose 

    cookie SERVERIDWEB insert indirect nocache secure 

    option forwardfor 

    http-request set-header X-Forwarded-Port %[dst_port] 

    http-request add-header X-Forwarded-Proto https if { ssl_fc } 

    server app-1 app1.example.com:8080 check cookie app1web 

    server app-2 app2.example.com:8080 check cookie app2web 

    server app-3 app3.example.com:8080 check cookie app3web 

回答

0

嘗試使用acl is_root path -i /這將匹配到一個空的上下文(https://www.example.com/
然後重定向所有匹配會話到https://www.example.com/aks
之後匹配規則到web_url

即:

acl is_root path -i/
acl is_domain hdr(host) -i www.example.com 
redirect code 301 location https://www.example.com/aks if is_domain is_root 
acl web_url path_beg /aks 
use_backend WEB if web_url 
+0

其實,'is_root -i /'不起作用,因爲它出現了,即使瀏覽器欄中沒有顯示,也有可能是/HTTP1.1 –