HAProxy community

Haproxy use_backend condition (acl) is missing the backend

I have an application which I installed in two servers for balancing issue.

I wanted to route the traffic like below:

server 1: client server 2: admin

server 1 app config: host: 192.168.0.101 port: 5031

server 2 app config: host: 192.168.0.102 port: 5032

Application is same in both servers with same database connection.

I installed haproxy in 192.168.0.101 with port 5033 and setup:

frontend hh-test
        bind 192.168.0.101:5033
        mode tcp
        option tcplog
        acl is_admin path_reg ^/admin/sales$
        use_backend server2 if is_admin
        default_backend server1

backend server2
        mode tcp
        server admin 192.168.0.102:5032

backend server1
        mode tcp
        server client 192.168.0.101:5031

It does work. When I access http://192.168.0.101:5033 It serves from Server 1 and when I access http://192.168.0.101:5033/admin/sales it serves from server2 …as expected. But some request goes to server1 accessing same /admin/sales url. Very few. I am not sure what I am doing wrong that some request goes to the other backend. Can I have an insight please?

You need to use mode http here, otherwise haproxy cannot reliably extract the URI.

1 Like

I think it is working now. Thank you, thanks a lot. @lukastribus Let me implement it in production and update the solution here.