0

In HAProxy (1.5) I have this rule to redirect all requests to a canonical domain:

redirect prefix https://domain.tld code 301 unless { hdr(host) -i domain.tld }

This works fine. However, I also have stats enabled (stats uri /haproxy-stats). For these I would like to disable the redirect as I need to access specific haproxy machines (they are behind a DNS round-robin) through their own host name.

Is there any way of configuring HAProxy in such a way?

1 Answer 1

1

This can be done using an ACL rule:

acl url_stats path /haproxy-stats
redirect prefix https://domain.tld code 301 unless { hdr(host) -i domain.tld or url_stats }

Using an anonymous ACL works too:

redirect prefix https://domain.tld code 301 unless { hdr(host) -i domain.tld } || { path /haproxy-status }

However, it turned out to be not needed at all as HAProxy doesn't apply redirect rules to the stats url; probably I had an old 301 redirect cached.

5
  • Can you nest a named ACL inside an anonymous one? I would have assumed ... unless { hdr(host) -i domain.tld } || url_stats would be the syntax... although the named ACL could be dropped, and just use ... unless { hdr(host) -i domain.tld } || { path /haproxy-stats } Apr 7, 2017 at 10:51
  • Oh, didn't know about anonymous ACLs. good to know. I'll test it and update my answer accordingly Apr 7, 2017 at 10:51
  • Testing is good. For some reason, the docs sort of downplay the { } anonymous ACL construct, as though named ACLs are easier... but I find it much tidier unless there are several matching cases or the same condition is tested repeatedly (in which case, named ACLs are a good way to avoid forgetting to change the test everywhere it occurs). Apr 7, 2017 at 10:57
  • Interesting, when testing again I noticed that even without this ACL I don't get a redirect. It seems like the redirects aren't applied to the stats at all. Maybe I had a cached 301 from before I had setup the stats. Apr 7, 2017 at 11:03
  • I was going to ask about that :) but all of my stuff is 1.6+, so I thought that might explain it. The stats hook is handled very early in request processing. Apr 7, 2017 at 11:09

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .