I need to set up a HAProxy to work in a following way. Let's say I have only 10 users and 10 backend servers. My goal is to stick each user to his own server based on custom http header user_id
. It means, that user's requests with header user_id=1
will be sent only to server1
(or any idle server) and no one is able to connect to this server anymore until connection is closed. I tried to test with such configuration
defaults
mode http
option http-server-close
option http-buffer-request
timeout client 25s
timeout connect 5s
timeout server 25s
timeout http-keep-alive 60s
timeout http-request 15s
frontend http-in
bind *:5000
default_backend servers
backend servers
balance hdr(user_id)
option httpchk GET /check HTTP/1.0
server server1 localhost:5001 check
server server2 localhost:5002 check
server server3 localhost:5003 check
Then I use
curl -XPOST --header "user_id=1" http://127.0.0.1:5000
but this balancing works like roundrobin
and requests are not being sticked to one server. The balance source
is not an option in my case, because users can use the same ip address. Summarizing: my objective is to balance requests based on custom user_id
header that any unique user_id
will use the same own backend server each time. Can anyone help me?