Reputation: 33
We have a Online Test application which is used by students. we have 4 different servers and an Nginx above all of them to load balance traffic among all 4 servers.
As our application need sticky session (for one user , all request to one server) so i have enabled ip_hash algorithm for load balancing.
Now we have a situation where all students appear for online test in a computer lab which has private ip assigned to each systems and All pass via one internet gateway with Public IP.
Now when students appear for test load balancer get same origin IP for all students and due to ip_hash it sends all traffic to one server.
how to resolve this issue?
We have maintain Sticky session with equal load distribution.
Upvotes: 2
Views: 2960
Reputation: 5930
This documentation page describes why this is happening. The ip-hash
directive only hashes on the first 3 octets of the IP address.
You can use the hash $remote_addr;
instead to hash based on all 4 octets.
Upvotes: 0
Reputation: 6499
It looks like nginx+ at least can do load balancing based on cookies using the sticky
directive.
sticky cookie srv_id expires=1h
will set a cookie that indicates the server to use. This requires you're doing ssl termination at nginx. I don't know if the free version of nginx can do this. See documentation for details
Upvotes: 1