Stick session bases on cookie

Hi,

I am using cookie based session stickiness for out HAProxy config. We have 2 backend servers serving application request. Since we don’t use session replication, we want that request from same user should be served by same backend server. In production environment, it seems request from same user is getting served from different server in between. Though this happens intermittently. I am not sure whether configuration is correct. Here is relevant section from our haproxy.cfg

backend nodes
mode http
balance source
hash-type consistent
option forwardfor
option httpchk HEAD / HTTP/1.1\r\nHost:localhost
cookie appserver insert indirect nocache
server app1 x.x.x.1:8081 weight1 maxconn 512 check cookie a1
server app2 x.x.x.2.8081 weight1 maxconn 512 check cookie a2

  1. Does server name has to be same as that of cookie value. i.e. In my case, Instead of
    server app1 x.x.x.1:8081 weight1 maxconn 512 check cookie a1
    I should change it to
    server app1 x.x.x.1:8081 weight1 maxconn 512 check cookie app1

  2. If this is not the problem, is there anything else that I should configure?

Thanks for all the help.

Amod