Cookie prefix with dynamic server template

Viewed 777

I am trying to implement sticky sessions. I have found out that I can add a prefix to the exiting cookies servers to identify them. See here for more

backend bk_web
  balance roundrobin
  cookie JSESSIONID prefix nocache
  server s1 192.168.10.11:80 check cookie s1
  server s2 192.168.10.21:80 check cookie s2

My problem is that I do not have distinct servers which I could hard code the cookie names for. Such as s1 and s2.

backend java_container
    balance roundrobin
    cookie JSESSIONID prefix nocache
    server-template worker- 6 worker:8080 check resolvers docker init-addr libc,none

I know the server will be named later worker-1, worker-2 etc but I can't figure out how to give this dynamic info as cookie name. Ideally it would be something like

server-template worker- 6 worker:8080 check resolvers docker init-addr libc,none cookie worker
2 Answers

I tried munging the snippets together and it actually worked.

backend java_container
    balance leastconn
    dynamic-cookie-key MYKEY
    cookie JSESSIONID prefix dynamic nocache
    server-template worker- 6 worker:8080 check resolvers docker init-addr libc,none

Cookie looks like this now where the first part the hashed server IP.

JSESSIONID: 8a90ee411f256174~602EE52C3C605D45070366D4009EED56

https://www.haproxy.com/blog/whats-new-haproxy-1-8/#dynamic-cookies

You are looking for the dynamic option as part of the cookie directive. You will also want to look into dynamic-cookie-key.

Related