Haproxy ACL for balance on URL request

31,640

I don't know if it is an actual issue, but you don't need to escape slashes in HAProxy's regexes. Also, in your stated case, you don't even need regexes but can use simple string matchers. They are magnitudes faster than regexes. So your ACLs could look like this:

acl msg-url-3 url_beg /path/mail/
acl msg-url-4 url_beg /path/wazap/

If no server is available in a dispatched backend, HAProxy will return an HTTP 503 response. You can use errorloc or errorfile to customize the response.

But it could be that I slightly misunderstood your issue. It's not very clear what exactly is not working as expected.

Share:
31,640

Related videos on Youtube

Elgreco08
Author by

Elgreco08

Updated on September 18, 2022

Comments

  • Elgreco08
    Elgreco08 almost 2 years

    I'm usung Ubuntu with haproxy 1.4.13 version.

    Its load balancing two subdomains:

    • app1.domain.com
    • app2.domain.com

    now i want to be able to use ACL to send based on url request to the right backends For example:

    http://app1.domain.com/path/games/index.php  sould be send to backend1
    http://app1.domain.com/path/photos/index.php should be send to backend2
    
    http://app2.domain.com/path/mail/index.php  sould be send to backend3
    http://app2.domain.com/path/wazap/index.php should be send to backend4
    

    i did used the code the the following acl

    frontend http-farm
            bind 0.0.0.0:80
            acl app1web     hdr_beg(host) -i app1  # for http://app1.domain.com
            acl app2web     hdr_beg(host) -i app2  # for http://app2.domain.com
    
    acl msg-url-1 url_reg ^\/path/games/.*
    acl msg-url-2 url_reg ^\/path/photos/.*
    acl msg-url-3 url_reg ^\/path/mail/.*
    acl msg-url-4 url_reg ^\/path/wazap/.*
    
    use_backend games  if  msg-url-1 app1web
    use_backend photos if  msg-url-2 app2web
    use_backend mail if .....
    
    
    
    backend games
            option httpchk GET /alive.php HTTP/1.1\r\nHost:\ app1.domain.com
            option  forwardfor
            balance roundrobin
            server  appsrv-1  192.168.1.10:80  check inter 2000 fall 3
            server  appsrv-2  192.168.1.11:80  check inter 2000 fall 3
    
    backend photos
            option httpchk GET /alive.php HTTP/1.1\r\nHost:\ app2.domain.com
            option  forwardfor
            balance roundrobin
            server  appsrv-1  192.168.1.13:80  check inter 2000 fall 3
            server  appsrv-2  192.168.1.14:80  check inter 2000 fall 3
    

    ....

    Since the path mail, photos...etc will be application pools on iis, i want to monitor them if they are alive, if the pool does not respond it should stop serving it.

    my problem is for sure in the regular expression in the ACL acl msg-url-4 url_reg ^/path/wazap/.*

    What should i change in the ACL to make it work ?

    thanks for any hints

  • Elgreco08
    Elgreco08 about 13 years
    Yes the url_beg did the job. If i want to say to backend to use if ACL is msg_url-3 AND appweb1 : use_backend if msg-url-3 appweb1 : use_backend if msg-url-3 & appweb1