<html><head></head><body><div style="color:#000; background-color:#fff; font-family:HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif;font-size:12px"><div id="yui_3_16_0_ym19_1_1479259405231_12252">Hi,</div><div id="yui_3_16_0_ym19_1_1479259405231_12217"><br></div><div dir="ltr" id="yui_3_16_0_ym19_1_1479259405231_12251">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:</div><div dir="ltr" id="yui_3_16_0_ym19_1_1479259405231_12218"><br></div><div dir="ltr" id="yui_3_16_0_ym19_1_1479259405231_12219">1. Client tries to access localhost:81/some/resource without signing in first;</div><div dir="ltr" id="yui_3_16_0_ym19_1_1479259405231_12250">2. Nginx redirect the client to localhost/login;</div><div dir="ltr" id="yui_3_16_0_ym19_1_1479259405231_12220">3. After user signed in, it failed to redirect the user back to localhost:81/some/resource;</div><div dir="ltr" id="yui_3_16_0_ym19_1_1479259405231_12221"><br></div><div dir="ltr" id="yui_3_16_0_ym19_1_1479259405231_12222">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:</div><div dir="ltr" id="yui_3_16_0_ym19_1_1479259405231_12223"><br></div><div dir="ltr" id="yui_3_16_0_ym19_1_1479259405231_12224"><font face="Courier New, courier, monaco, monospace, sans-serif" id="yui_3_16_0_ym19_1_1479259405231_12348">http: {</font></div><div dir="ltr" id="yui_3_16_0_ym19_1_1479259405231_12224"><font face="Courier New, courier, monaco, monospace, sans-serif" id="yui_3_16_0_ym19_1_1479259405231_12390"> upstream backend1 {</font></div><div dir="ltr" id="yui_3_16_0_ym19_1_1479259405231_12224"><font face="Courier New, courier, monaco, monospace, sans-serif" id="yui_3_16_0_ym19_1_1479259405231_12345"> server 127.0.0.1:4000;</font></div><div dir="ltr" id="yui_3_16_0_ym19_1_1479259405231_12224"><font face="Courier New, courier, monaco, monospace, sans-serif"> }</font></div><div dir="ltr" id="yui_3_16_0_ym19_1_1479259405231_12224"><font face="Courier New, courier, monaco, monospace, sans-serif"><br></font></div><div dir="ltr" id="yui_3_16_0_ym19_1_1479259405231_12370"><font face="Courier New, courier, monaco, monospace, sans-serif" id="yui_3_16_0_ym19_1_1479259405231_12371"> upstream backend2 {</font></div><div dir="ltr" id="yui_3_16_0_ym19_1_1479259405231_12372"><font face="Courier New, courier, monaco, monospace, sans-serif" id="yui_3_16_0_ym19_1_1479259405231_12373"> server 127.0.0.1:5000;</font></div><div dir="ltr" id="yui_3_16_0_ym19_1_1479259405231_12374"><font face="Courier New, courier, monaco, monospace, sans-serif" id="yui_3_16_0_ym19_1_1479259405231_12375"> }</font></div><div dir="ltr" id="yui_3_16_0_ym19_1_1479259405231_12374"><font face="Courier New, courier, monaco, monospace, sans-serif"><br></font></div><div dir="ltr" id="yui_3_16_0_ym19_1_1479259405231_12374"><font face="Courier New, courier, monaco, monospace, sans-serif"> server {</font></div><div dir="ltr" id="yui_3_16_0_ym19_1_1479259405231_12374"><font face="Courier New, courier, monaco, monospace, sans-serif"> listen 80;</font></div><div dir="ltr" id="yui_3_16_0_ym19_1_1479259405231_12374"><font face="Courier New, courier, monaco, monospace, sans-serif"><br></font></div><div dir="ltr" id="yui_3_16_0_ym19_1_1479259405231_12374"><font face="Courier New, courier, monaco, monospace, sans-serif" id="yui_3_16_0_ym19_1_1479259405231_12414"> location / {</font></div><div dir="ltr" id="yui_3_16_0_ym19_1_1479259405231_12374"><font face="Courier New, courier, monaco, monospace, sans-serif" id="yui_3_16_0_ym19_1_1479259405231_12413"> proxy_pass http://backend1/;</font></div><div dir="ltr" id="yui_3_16_0_ym19_1_1479259405231_12374"><font face="Courier New, courier, monaco, monospace, sans-serif" id="yui_3_16_0_ym19_1_1479259405231_12729"> }</font></div><div dir="ltr" id="yui_3_16_0_ym19_1_1479259405231_12374"><font face="Courier New, courier, monaco, monospace, sans-serif"><br></font></div><div dir="ltr" id="yui_3_16_0_ym19_1_1479259405231_12374"><font face="Courier New, courier, monaco, monospace, sans-serif"> location = /login {</font></div><div dir="ltr" id="yui_3_16_0_ym19_1_1479259405231_12374"><font face="Courier New, courier, monaco, monospace, sans-serif" id="yui_3_16_0_ym19_1_1479259405231_12517"> proxy_pass <a href="http://backend1/login;" id="yui_3_16_0_ym19_1_1479259405231_12516">http://backend1/login;</a></font></div><div dir="ltr" id="yui_3_16_0_ym19_1_1479259405231_12374"> proxy_set_header Cookie "redirect_to=$http_referer";</div><div dir="ltr" id="yui_3_16_0_ym19_1_1479259405231_12374"><font face="Courier New, courier, monaco, monospace, sans-serif"> }</font></div><div dir="ltr" id="yui_3_16_0_ym19_1_1479259405231_12374"><font face="Courier New, courier, monaco, monospace, sans-serif" id="yui_3_16_0_ym19_1_1479259405231_12469"> }</font></div><div dir="ltr" id="yui_3_16_0_ym19_1_1479259405231_12374"><font face="Courier New, courier, monaco, monospace, sans-serif"><br></font></div><div dir="ltr" id="yui_3_16_0_ym19_1_1479259405231_12374"><font face="Courier New, courier, monaco, monospace, sans-serif"> server {</font></div><div dir="ltr" id="yui_3_16_0_ym19_1_1479259405231_12374"><font face="Courier New, courier, monaco, monospace, sans-serif"> listen 81;</font></div><div dir="ltr" id="yui_3_16_0_ym19_1_1479259405231_12374"><font face="Courier New, courier, monaco, monospace, sans-serif"><br></font></div><div dir="ltr" id="yui_3_16_0_ym19_1_1479259405231_12374"><font face="Courier New, courier, monaco, monospace, sans-serif"> location / {</font></div><div dir="ltr" id="yui_3_16_0_ym19_1_1479259405231_12374"><font face="Courier New, courier, monaco, monospace, sans-serif"> auth_request /auth-proxy;</font></div><div dir="ltr" id="yui_3_16_0_ym19_1_1479259405231_12374"><font face="Courier New, courier, monaco, monospace, sans-serif" id="yui_3_16_0_ym19_1_1479259405231_12769"> error_page 401 =302 <a href="http://localhost/login;" id="yui_3_16_0_ym19_1_1479259405231_12768">http://localhost/login;</a></font></div><div dir="ltr" id="yui_3_16_0_ym19_1_1479259405231_12374"> proxy_pass http://backend2/;</div><div dir="ltr" id="yui_3_16_0_ym19_1_1479259405231_12374"><font face="Courier New, courier, monaco, monospace, sans-serif"> }</font></div><div dir="ltr" id="yui_3_16_0_ym19_1_1479259405231_12374"><font face="Courier New, courier, monaco, monospace, sans-serif"><br></font></div><div dir="ltr" id="yui_3_16_0_ym19_1_1479259405231_12374"><font face="Courier New, courier, monaco, monospace, sans-serif"> location = /auth-proxy {</font></div><div dir="ltr" id="yui_3_16_0_ym19_1_1479259405231_12374"><font face="Courier New, courier, monaco, monospace, sans-serif"> internal;</font></div><div dir="ltr" id="yui_3_16_0_ym19_1_1479259405231_12374"> ... ...</div><div dir="ltr" id="yui_3_16_0_ym19_1_1479259405231_12374"><font face="Courier New, courier, monaco, monospace, sans-serif"> }</font></div><div dir="ltr" id="yui_3_16_0_ym19_1_1479259405231_12374"><font face="Courier New, courier, monaco, monospace, sans-serif"> }</font></div><div dir="ltr" id="yui_3_16_0_ym19_1_1479259405231_12224"><font face="Courier New, courier, monaco, monospace, sans-serif" id="yui_3_16_0_ym19_1_1479259405231_12350">}</font></div><div dir="ltr" id="yui_3_16_0_ym19_1_1479259405231_12224"><br></div><div dir="ltr" id="yui_3_16_0_ym19_1_1479259405231_12224">Can someone please help?</div><div dir="ltr" id="yui_3_16_0_ym19_1_1479259405231_12224"><br></div><div dir="ltr" id="yui_3_16_0_ym19_1_1479259405231_12224">Thanks!</div><div dir="ltr" id="yui_3_16_0_ym19_1_1479259405231_12224">Yongtao</div></div></body></html>