i want use nginx load balancer in front of several node.js application nodes.
round-robin
, ip_hash
methods unbelievably easy implement in use case, they're not best fit.
i need nginx serve clients backend nodes in respect session id's given first-landed node.
during googlings, i've come "hash"ing method couldn't find many resources around.
here tried:
my_site.conf:
http { upstream my_servers { hash $remote_addr$http_session_id consistent; server 127.0.0.1:3000; server 127.0.0.1:3001; server 127.0.0.1:3002; } server { listen 1234; server_name example.com; location / { proxy_pass http://my_servers; proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504; proxy_redirect off; proxy_buffering off; proxy_set_header x-real-ip $remote_addr; proxy_set_header x-forwarded-for $proxy_add_x_forwarded_for; } } }
and @ application, return session-id
header session id.
res.setheader('session-id', req.sessionid);
i'm missing something, what?
$http_session_id
refers header sent client (browser), not application response. , need http://nginx.org/r/sticky, it's in commercial subscription only.
there third-party module same commercial one, you'll have recompile nginx.