我看到HAProxy的一些非常奇怪的行为。 我有下面的设置,以允许example.com/wiki去一个服务器和example.com/去另一个。 麻烦的是,/ wiki只有一半的时间,/ webserver只有一半的时间。 仔细检查后,似乎是在两个后端之间切换; 可能对它们进行负载平衡,而不是根据ACL规则转到特定的后端。
另一个奇怪的是,即使规则明确指出只有服务器的临时主机应该到达后端,services-staging.example.com/greenoven和staging.example.com都会去金橘。
我的HAProxyconfiguration有问题吗? 我是否正确使用acls或后端?
global log 127.0.0.1 local1 debug maxconn 200000 chroot /var/lib/haproxy user haproxy group haproxy daemon #debug #quiet defaults log global mode http option httplog option dontlognull retries 3 option redispatch maxconn 200000 contimeout 5000 clitimeout 50000 srvtimeout 50000 stats uri /monitor stats auth admin:GS01 stats refresh 5s stats enable frontend http-in bind *:80 option forwardfor #Staging Hosts acl host_staging hdr(host) -i staging.example.com acl host_staging_services hdr(host) -i staging-services.example.com #Production Hosts acl host_prod hdr(host) -i example.com www.example.com acl host_prod_services hdr(host) -i services.urbanatla.com #URL Paths acl url_wiki url_beg /wiki acl url_go url_beg /greenoven acl url_arcgis url_beg /ArcGIS #Staging Backends use_backend pluto if host_staging_services url_arcgis use_backend kumquat if host_staging_services url_go use_backend kumquat if host_staging url_wiki use_backend cumberland if host_staging #Production Backends use_backend saturn if host_prod_services url_arcgis use_backend willow if host_prod_services url_go use_backend willow if host_prod url_wiki use_backend ganges if host_prod backend kumquat server kumquat kumquat.example.com:8080 maxconn 5000 backend cumberland server cumberland cumberland.example.com:80 maxconn 5000 backend ganges server ganges ganges.example.com:80 maxconn 5000 backend articdata server articdata articdata.example.com:80 maxconn 5000 backend saturn server saturn saturn.example.com:80 maxconn 5000 backend willow server willow willow.example.com:8080 maxconn 5000 backend pluto server pluto pluto.example.com:80 maxconn 5000
它看起来像是重复使用连接,当你做上下文切换时,你不应该这样做。 我添加了以下内容:
option httpclose
每篇文章: 为什么我在我的HAProxy内容切换configuration中出现错误? 。
所有url和网域现在都能正常运作。
如果你阅读haproxy 文档 ,你可以find这个段落:
hdr(name) The HTTP header <name> will be looked up in each HTTP request. Just as with the equivalent ACL 'hdr()' function, the header name in parenthesis is not case sensitive. If the header is absent or if it does not contain any value, the roundrobin algorithm is applied instead.
这可以解释为什么haproxy在不遵循ACL的服务器之间进行负载平衡。 为了确保,你需要检查你是否真的获得host头的请求。
我认为你可以使用目标IP,名称或URL而不是检查host头。