Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have some logic in a frontend that routes to different backends based on both the host and the url. Logically it looks like this:

if hdr(host) ends with '':
    if url starts with '/dir1/':
        use backend
    elif url starts with '/dir2/':
        use backend
    # ... else if ladder repeats on different dirs
elif hdr(host) ends with '':
    # another else if ladder exactly the same as above
    # ...
# ... else if ladder repeats like this on different domains

Is there a way to group acls to avoid having to repeatedly check the domain acl?

Obviously there needs to be a use backend statement for each possibility, but I don't want to have to check the domain over and over because it's very inefficient.

In other words, I want to avoid this:

use backend if and acl-url1
use backend if and acl-url2
use backend if and acl-url3
# tons more possibilities below

because it has to keep checking

This is particularly an issue because I have specific rules for subdomains such as and, but I want to fall back on the most common case of * That means every single rule that uses a specific subdomain must be checked prior to * which makes it even more inefficient for the common case.

share|improve this question
You might want to check section 7.7 of the HAProxy manual: Using ACLs to form conditions. Also, if it hurts you eyes like it did with mine, I am maintaining a more readable version at – tmslnz Mar 10 '11 at 23:30
For reference, this appears to have moved to section 7.2 of the documentation for HAProxy version 1.5.9. – ghoti Dec 1 '14 at 20:34

Are you running into performance problems with your current application?

If you definitely need to improve performance at the HAProxy level, then I would suggest simply using a separate HAProxy instance for each subdomain. For example, create a new HAProxy server, and point directly to the new server. You can also continue pointing all DNS entries to the main HAProxy server, and have the first HAProxy layer only handle subdomain matching.

Of course, if you don't really have performance problems, then maybe it's better to leave well enough alone.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.