【问题标题】:Forwarding default URL to specific URI in HAProxy将默认 URL 转发到 HAProxy 中的特定 URI
【发布时间】:2016-12-31 04:54:58
【问题描述】:

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

【问题讨论】:

    标签: haproxy


    【解决方案1】:

    尝试使用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
    

    【讨论】:

    • 其实`is_root -i /`是不行的,因为它出现了,即使浏览器栏中没有显示,也可能是/HTTP1.1里面有东西
    猜你喜欢
    • 2013-10-27
    • 1970-01-01
    • 1970-01-01
    • 2019-03-12
    • 1970-01-01
    • 1970-01-01
    • 2017-12-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多