给出以下HAProxy配置:
acl acl-api-qa hdr(host) -i qa.example.com
use_backend backend-api-qa if acl-api-qa
backend backend-api-qa
mode http
balance leastconn
server-template api 10 _api._env=qa.service.consul resolvers consul resolve-prefer ipv4 check
acl acl-api-test hdr(host) -i test.example.com
use_backend backend-api-test if acl-api-test
backend backend-api-test
mode http
balance leastconn
server-template api 10 _api._env=test.service.consul resolvers consul resolve-prefer ipv4 check
流量仅路由到qa.example.com,但test.example.com是503:服务不可用,因为HAProxy在遇到第一个后端并忽略下一组ACl和后端时似乎会短路。这是订购问题吗?我不能交织ACL和后端吗?是否应该将它们构建为ACL部分,然后再构建一个Backends部分?
答案 0 :(得分:0)
似乎是这样吗?这对我有用:
acl acl-api-test hdr(host) -i test.example.com
acl acl-api-qa hdr(host) -i qa.example.com
use_backend backend-api-test if acl-api-test
use_backend backend-api-qa if acl-api-qa
backend backend-api-test
mode http
balance leastconn
server-template api 10 _api._env=test.service.consul resolvers consul resolve-prefer ipv4 check
backend backend-api-qa
mode http
balance leastconn
server-template api 10 _api._env=qa.service.consul resolvers consul resolve-prefer ipv4 check
但是在领事模板中导致相当多的重复代码。 HAProxy是否期望将acl
,use-backend
和backend
分为不同的组?