Search code examples
cookiesstickyhaproxy

Haproxy configuration with sticky `app set` cookie


I have a cookie setup by my app that represents a room. I want all users belonging to the same room to connect to the same server.

With the classic cookie sticky scheme I do not want Haproxy to write a cookie for me or use the cookie value as the server name. There seems to be an other configuration possible where it uses a cookie pre set in the response and maps it a random (leastconn) server. The effect if that any subsequent connections with the same cookie will point to the same server.

peers servers
    peer server1 192.168.10:8888 check
    peer server2 192.168.10:8889 check
    peer server3 192.168.10:8890 check

backend myapp
    balance     leastconn
    option      forwardfor
    stick-table type string len 12 size 20M expire 360m peers servers
    stick store-request req.cook_val(my_cookie_room_id)
    stick match req.cook_val(my_cookie_room_id)

I get the following error:

[ALERT] 069/102505 (1170) : parsing [haproxy.cfg:26] : 'stick': unknown fetch method 'req.cook_val(sticky_room_id)'.


Solution

  • Haproxy 1.4 had a different syntax.