Is it possible to do stickiness based on the io cookie or custom http headers in NGINX? #4966
Unanswered
antonander
asked this question in
Q&A
Replies: 1 comment
-
Hi! Unfortunately, the Reference: https://nginx.org/en/docs/http/ngx_http_upstream_module.html#sticky_cookie |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello, all.
TLDR; Is it possible to do stickiness in NGINX based on the socket.io cookie (io) or a custom HTTP header? Or is this only possible with the IP?
I am currently looking at running an application on multiple nodes. We use NGINX and want to keep the support for polling as transport method.
The docs (https://socket.io/docs/v4/using-multiple-nodes#nginx-configuration) show an example of the configuration needed in NGINX to do the load-balancing with stickiness based on the
ip_hash
orhash $remote_addr consistent
methods.This works fine, I am looking, however, at being able to do this with the cookie set. In the docs related to cookies (https://socket.io/how-to/deal-with-cookies#cookie-based-sticky-session), it mentions:
My attempt to do this with NGINX Open Source looks something like this:
This sort of works, I don't get as many 400 errors, but I still end up with some. It can stablish a successful connection after a few attempts, but it still seems odd. I don't see this happening when using
ip_hash
. I see the cookie is indeed included in the requests. This is the server setup:I also tried to add a custom header (https://socket.io/docs/v3/client-initialization/#extraheaders) and use that to do the load balancing:
But I got the same result as with
$cookie_io
I'm trying to debug the issue, but I wonder, is this even supported? I see no indication or example on how to do this with NGINX.
Thanks in advance.
Beta Was this translation helpful? Give feedback.
All reactions