Force use of a certain subset of backends in haproxy

haproxy

I'm setting up haproxy to use multiple backend servers but want one of them to handle particular requests:

backend bagend
        mode http
        balance roundrobin
        option httpchk GET / HTTP/1.1\r\nHost:\ www.example.com
        use-server app1_00 if { path_beg /frodo }
        use-server app1_01 if { path_beg /frodo }
        use-server app1_02 if { path_beg /frodo }
        use-server app1_03 if { path_beg /frodo }
        server  app1_00 10.0.0.1:9100 check
        server  app1_01 10.0.0.1:9101 check
        server  app1_02 10.0.0.1:9102 check
        server  app1_03 10.0.0.1:9103 check
        server  app2_00 10.0.0.2:9100 check
        server  app2_01 10.0.0.2:9101 check
        server  app2_02 10.0.0.2:9102 check
        server  app2_03 10.0.0.2:9103 check

Will my use-server commands balance across all 4 backends on app1? Or do I need to do this a different way? It looks as though everything is going to app1_00.

Best Answer

What you want to do is have an acl in the frontend send the request to a different backend based on the URL.

frontend shire
    bind *:80
    mode http
    acl path-frodo path_beg /frodo
    use backend longbottom if path-frodo
    default_backend bagend

backend longbottom
    mode http
    balance roundrobin
    option httpchk GET / HTTP/1.1\r\nHost:\ www.example.com
    server  app1_00 10.0.0.1:9100 check
    server  app1_01 10.0.0.1:9101 check
    server  app1_02 10.0.0.1:9102 check
    server  app1_03 10.0.0.1:9103 check

backend bagend
    mode http
    balance roundrobin
    option httpchk GET / HTTP/1.1\r\nHost:\ www.example.com
    server  app1_00 10.0.0.1:9100 check
    server  app1_01 10.0.0.1:9101 check
    server  app1_02 10.0.0.1:9102 check
    server  app1_03 10.0.0.1:9103 check
    server  app2_00 10.0.0.2:9100 check
    server  app2_01 10.0.0.2:9101 check
    server  app2_02 10.0.0.2:9102 check
    server  app2_03 10.0.0.2:9103 check

All request beginning with /frodo will hit only app1_00, app1_01, app1_02 and app1_03. All other requests will hit everything.