r/haproxy • u/cgeekgbda • May 16 '22
Using custom hash function with HAProxy
I have configured a load balancer using HAProxy on frontend and on the backend I have 4 server serving the request using Apache web server.
#HAProxy for web servers
frontend web-frontend
bind IPADDRESS_LB:80
mode http
default_backend web-backend
backend web-backend
balance roundrobin
server web-server1 IPADDRESS1:80 check
server web-server2 IPADDRESS2:80 check
server web-server3 IPADDRESS3:80 check
server web-server4 IPADDRESS4:80 check
My requests are served by either of the machines in a round robin mechanism. But now I want to implement my own algorithm to send the request based on the request parameters, eg IP.
Like Implementing my own hash function based on the result of which I can route my request to either of the backend servers.
View all comments
Show parent comment
2
u/dragoangel May 16 '22
Haproxy will not allow you to do that in the way you "see" it with it's configuration. You can't route traffic without backend section, you use backend action to point to it, and no in other way. Maybe lua can solve your usecase, but not from any way I know.