Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've seen that setting up load-balancing with nginx is pretty easy and i'd like to give it a try. My only concern is about sessions: how can I take advantage of nginx to route all the subsequent calls from a client to the same server to achieve session stickiness?

Thanks

share|improve this question
up vote 0 down vote accepted

use ip_hash directive

share|improve this answer

ip_hash is the loadbalance rule of nginx for session. However,the nginx server must get the real IP. if you use squid as the front server, then, the nginx server would get the IP of squid. Next, the nginx must direct the real server. If there are other loadbalancing servers after the nginx server, the session would not be send on the same real server.

share|improve this answer

As alternative you can look at Nginx Sticky Module

When dealing with several backend servers, it's sometimes useful that one client (browser) is always served by the same backend server (for session persistence for example).

Using a persistence by IP (with the ip_hash upstream module) is maybe not a good idea because there could be situations where a lot of different browsers are coming with the same IP address (behind proxies)and the load balancing system won't be fair.

Using a cookie to track the upstream server makes each browser unique.

When the sticky module can't apply, it switchs back to the classic Round Robin Upstream or returns a "Bad Gateway" (depending on the no_fallback flag).

Sticky module can't apply when cookies are not supported by the browser

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.