Haproxy Too Many Redirects

1.2k views Asked by At

I want to route trafic outside of Turkey to another domain, I write acl into haproxy so in Turkey it works as planned but outside of Turkey traffic redirects but shows too many redirects. What I am missing in this configuration. My traffic comes from 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
1

There are 1 answers

0
Holger Just On

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.