HAproxy path_beg 不重定向

HAproxy path_beg not redirect

我需要使用 path_beg 但似乎不起作用,我的配置文件是:

global
    log 127.0.0.1 local0
    maxconn 4096

defaults
    log global
    mode http
    option httplog
    option dontlognull
    retries 3
    option redispatch
    maxconn 2000
    timeout connect 600000
    timeout client 600000
    timeout server 600000

frontend http-in
    bind *:80

    acl foo     hdr(host)   -i  www.example.com
    acl bar     path_beg    /bar

    use_backend foo-cluster     if  foo
    use_backend bar-cluster     if  bar

backend foo-cluster
    balance roundrobin
    option http-server-close
    option forwardfor
    http-request set-header X-Client-IP %[src]
    server foo 172.51.0.201:80

backend bar-cluster
    balance roundrobin
    option http-server-close
    option forwardfor
    http-request set-header X-Client-IP %[src]
    server bar 172.51.0.202:80

后端 foo-cluster 工作,如果我去 http://www.example.com/bar 我有一个 404 未从 foo-cluster 找到,有什么想法吗? (使用 haproxy 1.7.7)

对于“http://www.example.com/bar”url,foo 和 bar ACL 都是 True。
由于首先评估 "use_backend foo_cluster" 然后您的请求将被路由到该后端,即使 bar ACL 为 True。
因此,您需要重新排序 "use_backend" 规则或在 ACL 定义中更具体。