I have an application that's running on two different AWS instances and I'd like to enable "sticky" or "persistent" sessions based on IP so that I can take advantage of web socket technologies in a particular way.
I have two different setups that both involve using ip_hash
to enable these sticky sessions.
In the first setup, the app processes are running on the same instance as the Nginx config. This is working, the sessions are persistent as expected.
upstream my_app {
ip_hash;
# local servers
server 127.0.0.1:3001 weight=100 max_fails=5 fail_timeout=300;
server 127.0.0.1:3002 weight=100 max_fails=5 fail_timeout=300;
keepalive 8;
}
In the second setup, I'm pointing to external instances and trying to achieve the same effect. This set up is not working. In other words, the sessions are still being load balanced.
upstream my_app {
ip_hash;
# external servers
server 111.11.11.11:3001 weight=100 max_fails=5 fail_timeout=300;
server 222.22.22.22:3002 weight=100 max_fails=5 fail_timeout=300;
keepalive 8;
}
Am I using ip_hash
correctly? How can I enable "sticky" ip-based sessions for external servers?