Two servers, one sign-in page?

Yongtao You yongtao_you at
Wed Nov 16 01:39:47 UTC 2016

I'm new to Nginx. I'm trying to configure Nginx as a reverse proxy to 2 backend services, as follows (see below). The backend1 server is already password protected, but backend2 is not. I'm trying to route backend2 sign-in to backend1 login page. The only thing that is not working is the following scenario:
1. Client tries to access localhost:81/some/resource without signing in first;2. Nginx redirect the client to localhost/login;3. After user signed in, it failed to redirect the user back to localhost:81/some/resource;
It seems the $http_referer is empty. How can I pass the original URL to the sign-in page so that it can redirect back? Here is my configuration:
http: {    upstream backend1 {        server;    }
    upstream backend2 {        server;    }
    server {        listen 80;
        location / {            proxy_pass http://backend1/;        }
        location = /login {            proxy_pass http://backend1/login;                          proxy_set_header Cookie "redirect_to=$http_referer";        }    }
    server {        listen 81;
        location / {            auth_request /auth-proxy;            error_page 401 =302 http://localhost/login;                          proxy_pass http://backend2/;        }
        location = /auth-proxy {            internal;                          ... ...        }    }}
Can someone please help?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the nginx mailing list