Score:0

HAProxy sticky cookie subdomains + deterministic balance

id flag

I have multiple subdomains (www.example.com and api.example.com, pretty standard I reckon), and I want to configure HAProxy to use sticky session cookie.

balance roundrobin
cookie NODE insert indirect nocache domain example.com

However, even though HAProxy indeed sets the cookie to my root domain, it won't read it using the root domain!

Therefore, when hitting www.example.com, "NODE" cookie is set to node1, but when making an API request, HAProxy does not find the cookie on api.example.com, and sets it again to a new value: node2.

Therefore, because my sessions are stored in Redis, and because I have one Redis instance per webserver (for performance reasons), my code cannot find the session, and fails.

Also, I tried using another algorithm for balance, which is supposed to be deterministic, but it did not work:

balance source
hash-type consistent

I still got "node1" on www and "node2" on api.

(I did clear all my cookies several times, restarted HAProxy, etc.)

Could someone please help me? I did read the HAProxy documentation for the "cookie" directive, and I also looked up online, but to no avail.

Thank you kindly.

Best,

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.