首页 > 解决方案 > Haproxy 重定向过多

问题描述

我想将土耳其以外的流量路由到另一个域,我将 acl 写入 haproxy,因此在土耳其它按计划工作,但在土耳其以外的流量重定向但显示的重定向太多。我在这个配置中缺少什么。我的流量来自 Cloudflare

acl acl_tr req.hdr(CF-IPCountry) eq "TR"
acl test_hname hdr(host) -m end lbtest.test.com
acl test_de hdr(host) -m end lbde.test.com
use_backend test_backends if acl_tr test_hname
redirect code 302 prefix https://lbde.test.com unless acl_tr
use_backend test_backends if test_de

标签: redirecthaproxyhaproxy-ingress

解决方案


If someone outside of Turkey accesses your site, they might get redirected once to https://lbde.test.com from your redirect rule. Assuming this hostname points to the same HAProxy instance, it will run into the very same redirect rule again, resulting in the same redirect to be sent.

To resolve this, you might want to leverage the test_de ACL there to not perform the redirect if the user is already requesting the lbde.test.com host:

redirect code 302 prefix https://lbde.test.com unless acl_tr || test_de

Finally, please make sure that you understand the order of rule evaluation in HAProxy. Although you have written your redirect rule after your first use_backend rule, it will still be evaluated before any use_backend rules.


推荐阅读