HAProxy-根据URI转发到其他Web服务器


14

我有一个具有以下配置的HTTP服务器场:

listen webfarm 10.254.23.225:80
       mode http
       balance roundrobin
       cookie SERVERID insert
       option httpclose
       option forwardfor
       option httpchk HEAD /check.txt HTTP/1.0
       server webA 10.254.23.4:80 cookie A check
       server webB 10.248.23.128:80 cookie B check

我想添加一些选项,它将针对特定URI(即/ special)的所有请求转发到第三台Web服务器。我该怎么办?

Answers:


23

这是我写的关于基于主机头的负载平衡的博客文章:

http://www.mattbeckman.com/2009/09/18/using-the-acl-in-haproxy-for-load-balancing-named-virtual-hosts/

如果要与URI或目录进行匹配,建议使用path_beg而不是该页面上提供的示例中使用的hdr_end。下面是如何使用配置执行此操作的示例:

frontend http-in
    bind 10.254.23.225:80
    acl has_special_uri path_beg /special
    use_backend special_server if has_special_uri
    default_backend webfarm

backend webfarm
    balance roundrobin
    cookie SERVERID insert
    option httpchk HEAD /check.txt HTTP/1.0
    option httpclose
    option forwardfor
    server webA 10.254.23.4:80 cookie webA check
    server webB 10.248.23.128:80 cookie webB check

backend special_server
    balance roundrobin
    cookie SERVERID insert
    option httpchk HEAD /check.txt HTTP/1.0
    option httpclose
    option forwardfor
    server webC 10.0.0.1:80 cookie webC check

希望有帮助!


嘿,直到现在才看到您的答案。我实际上已经使用相同的解决方案解决了它。感谢您的回答!
Saggi Malachi 2010年

该链接不再有效。但是,仍可以在此处查看:web.archive.org/web/20160404161136/http
//www.techrawr.com/2009/…– jaggedsoft '16

1
@NextLocal谢谢-我更新了链接。我让先前的域过期,但这是上面更新的链接的别名。
马特·贝克曼
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.