14

I have an HTTP farm with the following configuration:

listen webfarm 10.254.23.225:80
       mode http
       balance roundrobin
       cookie SERVERID insert
       option httpclose
       option forwardfor
       option httpchk HEAD /check.txt HTTP/1.0
       server webA 10.254.23.4:80 cookie A check
       server webB 10.248.23.128:80 cookie B check

I would like to add some option which would forward all requests for a specific URI (i.e /special) to a 3rd web server. How should I do it?

grateful.dev
  • 378
  • 1
  • 2
  • 8

1 Answers1

24

Here is a blog post I wrote on load balancing based on the host headers:

http://www.mattbeckman.com/2009/09/18/using-the-acl-in-haproxy-for-load-balancing-named-virtual-hosts/

If you would like to match against a URI or directory, I would suggest using path_beg instead of hdr_end that is used in the example provided on that page. Below is an example of how you might do this with your configuration:

frontend http-in
    bind 10.254.23.225:80
    acl has_special_uri path_beg /special
    use_backend special_server if has_special_uri
    default_backend webfarm

backend webfarm
    balance roundrobin
    cookie SERVERID insert
    option httpchk HEAD /check.txt HTTP/1.0
    option httpclose
    option forwardfor
    server webA 10.254.23.4:80 cookie webA check
    server webB 10.248.23.128:80 cookie webB check

backend special_server
    balance roundrobin
    cookie SERVERID insert
    option httpchk HEAD /check.txt HTTP/1.0
    option httpclose
    option forwardfor
    server webC 10.0.0.1:80 cookie webC check

Hope that helps!

Matt Beckman
  • 1,502
  • 18
  • 33
  • Hey, saw your answer only now. I've actually already solved it using this same solution. Thanks for your answer! – grateful.dev Apr 01 '10 at 22:14
  • This link is no longer alive. However, it is still viewable here: https://web.archive.org/web/20160404161136/http://www.techrawr.com/2009/09/18/using-the-acl-in-haproxy-for-load-balancing-named-virtual-hosts – jaggedsoft Oct 23 '16 at 18:58
  • 1
    @NextLocal Thanks -- I updated the link. I let the previous domain expire, but it was an alias to the updated link above. – Matt Beckman Oct 24 '16 at 23:16