Nginx load balancing to keep sessions between IIS servers

Francis Daly francis at
Fri Mar 27 08:30:41 UTC 2020

On Tue, Mar 24, 2020 at 06:01:35PM -0400, robe007 wrote:

Hi there,

> I have set up a load balancer with NGINX for two IIS web servers that works
> with sessions.

What is "a session"?

The answer to that may make it clear how to achieve what you want.

> upstream mybalancer {
>     ip_hash;
>     server;
>     server;
> }
> #Server
> server {
>     server_name;
>     location / { 
>     proxy_pass http://mybalancer; 
>     }   
> }
> When I make a request to it gets redirected -for example- to
> Next I make the login, go to a specific page, let's say:
> Everything is ok.

That... probably should not happen.

In a reverse proxy situation, your client should not know (or care)
whether it is talking to server1 or to server2 -- it only interacts
with server3.

(It is possible that I am just misunderstanding the terminology here.)

> Now I turn off, and NGINX redirects me to, but
> prompts me to the login page.

I think "no".

server2 asks you to login; nginx does not. And that difference matters

> It's possible to configure NGINX to keep the same sessions when one server
> goes down? This means that -in my example- NGINX could redirect me to
> with the same session.

Back to the first question -- what is a session?

I suspect that in your system it is "state stored on the back-end server1
or server2"; and it is not anything that the browser knows about and
not anything that nginx knows about. The browser might have a "key"
to the session in a cookie.

If that is the case, then the fix would be for you to make sure that
server1 and server2 both have the same shared idea of a session, so that
the same cookie sent to either server will end up with the same response.

And there is nothing the nginx can do about arranging that.

Francis Daly        francis at

More information about the nginx mailing list