Skip to content

nginx and ip_hash: examples/cluster-nginx uses always the same node #3778

Answered by darrachequesne
mcelotti asked this question in Q&A
Discussion options

You must be logged in to vote

That may be due to the fact the ip_hash only uses the first 3 octets of the client address (xxx.yyy.zzz.0).

From http://nginx.org/en/docs/http/ngx_http_upstream_module.html#ip_hash:

The first three octets of the client IPv4 address, or the entire IPv6 address, are used as a hashing key.

I have updated the example here: https://github.com/socketio/socket.io/blob/master/examples/cluster-nginx/nginx/nginx.conf

You can test it with multiple client containers and the hash $remote_addr consistent; directive:

$ docker-compose up --scale=client=10 client
client_9         | 
client_9         | > [email protected] start /usr/src/app
client_9         | > node index.js
client_9         | 
client…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@mcelotti
Comment options

Answer selected by mcelotti
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants