Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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 'a.domain.com':
    if url starts with '/dir1/':
        use backend domain.com/dir1/
    elif url starts with '/dir2/':
        use backend domain.com/dir2/
    # ... else if ladder repeats on different dirs
elif hdr(host) ends with 'b.domain.com':
    # 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 domain.com/url1/ if acl-domain.com and acl-url1
use backend domain.com/url2/ if acl-domain.com and acl-url2
use backend domain.com/url3/ if acl-domain.com and acl-url3
# tons more possibilities below

because it has to keep checking acl-domain.com.

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

share|improve this question

2 Answers 2

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 https://github.com/tmslnz/HAProxy_Markdown

share|improve this answer
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 a.domain.com 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.