Nginx load balancing to keep sessions between IIS servers

robe007 nginx-forum at
Tue Mar 24 22:01:35 UTC 2020

I have set up a load balancer with NGINX for two IIS web servers that works
with sessions. Here is the NGINX configuration file I have created for the
load balancing:

#Log Format
log_format upstreamlog '$server_name to: $upstream_addr [$request] '
    'upstream_response_time $upstream_response_time '
    'msec $msec request_time $request_time';

upstream mybalancer {

server {
    listen 80;
    listen [::]:80;

    access_log /var/log/nginx/access.log upstreamlog;

    location / { 
    proxy_pass http://mybalancer; 
    proxy_http_version 1.1; 
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-Host $server_name;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";

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.

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

My question:

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.


I have read on other posts about setting this options:

proxy_cookie_path ~*^/.* /;
add_header "Set-Cookie" "lb=$upstream_http_X_Loadbalance_ID";

but does not works.

Posted at Nginx Forum:,287447,287447#msg-287447

More information about the nginx mailing list