在HAProxy中将默认URL转发到特定URI

时间:2016-12-31 04:54:59

标签: haproxy

我是HAProxy的新手。我尝试配置HAProxy以将URL转发到特定的URI。 例如,我的网址为https://www.example.com,我想将其转发到https://www.example.com/aks/

我的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

1 个答案:

答案 0 :(得分: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