<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">
<div>
<div style="color: rgb(0, 0, 0); font-family: Calibri, sans-serif; font-size: 14px;">
In general try to avoid using the if directive too much.</div>
<div><font face="Calibri,sans-serif">https://www.nginx.com/resources/wiki/start/topics/depth/ifisevil/</font></div>
<div><font face="Calibri,sans-serif"><br>
</font></div>
<div>For what you're trying to do, using a map would be the cleanest (and nicest) way I believe – someone can correct me if they want :-D</div>
<div style="color: rgb(0, 0, 0); font-family: Calibri, sans-serif; font-size: 14px;">
<div id="MAC_OUTLOOK_SIGNATURE"></div>
</div>
</div>
<div style="color: rgb(0, 0, 0); font-family: Calibri, sans-serif; font-size: 14px;">
<br>
</div>
<span id="OLK_SRC_BODY_SECTION" style="color: rgb(0, 0, 0); font-family: Calibri, sans-serif; font-size: 14px;">
<div style="font-family:Calibri; font-size:12pt; text-align:left; color:black; BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 0in; PADDING-RIGHT: 0in; BORDER-TOP: #b5c4df 1pt solid; BORDER-RIGHT: medium none; PADDING-TOP: 3pt">
<span style="font-weight:bold">From: </span>nginx <<a href="mailto:nginx-bounces@nginx.org">nginx-bounces@nginx.org</a>> on behalf of Ajay Garg <<a href="mailto:ajaygargnsit@gmail.com">ajaygargnsit@gmail.com</a>><br>
<span style="font-weight:bold">Reply-To: </span>"<a href="mailto:nginx@nginx.org">nginx@nginx.org</a>" <<a href="mailto:nginx@nginx.org">nginx@nginx.org</a>><br>
<span style="font-weight:bold">Date: </span>Sunday, 9 April 2017 at 17.37<br>
<span style="font-weight:bold">To: </span>"<a href="mailto:nginx@nginx.org">nginx@nginx.org</a>" <<a href="mailto:nginx@nginx.org">nginx@nginx.org</a>><br>
<span style="font-weight:bold">Subject: </span>Re: URL-Rewriting not working<br>
</div>
<div><br>
</div>
<span style="mso-bookmark:_MailOriginalBody">
<blockquote id="MAC_OUTLOOK_ATTRIBUTION_BLOCKQUOTE" style="BORDER-LEFT: #b5c4df 5 solid; PADDING:0 0 0 5; MARGIN:0 0 0 5;">
<div>
<div>
<div dir="ltr">Hi Francis.<br>
<div class="gmail_extra"><br>
<div class="gmail_quote">On Sun, Apr 9, 2017 at 8:47 PM, Francis Daly <span dir="ltr">
<<a href="mailto:francis@daoine.org" target="_blank">francis@daoine.org</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<span>On Sun, Apr 09, 2017 at 06:36:51PM +0530, Ajay Garg wrote:<br>
<br>
Hi there,<br>
<br>
</span>> Got it Francis !!<br>
<br>
Good news.<br>
<span><br>
>                 location / {<br>
>                                         auth_basic 'Restricted';<br>
>                                         auth_basic_user_file<br>
> /home/20da689b45c84f2b80bc84d6<wbr>51ed573f/.htpasswd;<br>
><br>
>                                         if ($remote_user =<br>
> "20da689b45c84f2b80bc84d651ed5<wbr>73f") {<br>
>                                                 proxy_pass<br>
> <a href="https://127.0.0.1:2000" rel="noreferrer" target="_blank">https://127.0.0.1:2000</a>;<br>
>                                         }<br>
><br>
>                 }<br>
<br>
</span>When you come to add the second user, you will see that you want one<br>
file with all the user/pass details.<br>
</blockquote>
<div> </div>
<div><br>
</div>
<div>Yes, I have already changed it to use just one file.<br>
</div>
<div>Upon that, would not just multiple sections of "if" checks for $remote_user suffice, something like ::<br>
<br>
#########################################################################<br>
server {<br>
                listen 2000 ssl;<br>
<br>
                ssl_certificate /etc/nginx/ssl/nginx.crt;<br>
                ssl_certificate_key /etc/nginx/ssl/nginx.key;<br>
<br>
                location / {<br>
                              <wbr>          auth_basic 'Restricted';<br>
                              <wbr>          auth_basic_user_file /etc/nginx/ssl/.htpasswd;<br>
<br>
                              <wbr>          if ($remote_user =  "user1") {<br>
                              <wbr>                  proxy_pass <a href="https://127.0.0.1:2000" target="_blank">
https://127.0.0.1:2001</a>;<br>
                              <wbr>          }<br>
<br>
                                        if ($remote_user =  "user2") {<br>
                              <wbr>                  proxy_pass <a href="https://127.0.0.1:2000" target="_blank">
https://127.0.0.1:2002</a>;<br>
                              <wbr>          }<br>
<br>
                              <wbr>         # and so on ....<br>
<br>
                }<br>
         }<br>
#########################################################################<br>
<br>
</div>
<div>Looking forward to hearing back from you.<br>
<br>
<br>
</div>
<div>Thanks and Regards,<br>
</div>
<div>Ajay<br>
</div>
<div><br>
</div>
<div><br>
 </div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
You will probably also see that it will be good to use a map<br>
(<a href="http://nginx.org/r/map" rel="noreferrer" target="_blank">http://nginx.org/r/map</a>) to set a variable for the port to connect to,<br>
based on $remote_user. Then your main config becomes just "proxy_pass<br>
<a href="http://127.0.0.1:$per_user_por">http://127.0.0.1:$per_user_por</a><wbr>t;".<br>
<br>
Note that I have not tested that, and expect that there may be some more<br>
subtleties involved, such as perhaps requiring an explicit proxy_redirect<br>
directive.<br>
<br>
Note also that you will probably want to set a default value for<br>
$per_user_port, and make sure that something sensible happens when that<br>
value is used -- probably a response along the lines of "something isn't<br>
fully set up on the server yet; please wait or let us know", so the user<br>
is not confused.<br>
<div class="gmail-m_4983239477093541800HOEnZb">
<div class="gmail-m_4983239477093541800h5"><br>
Good luck with it,<br>
<br>
        f<br>
--<br>
Francis Daly        <a href="mailto:francis@daoine.org" target="_blank">francis@daoine.org</a><br>
______________________________<wbr>_________________<br>
nginx mailing list<br>
<a href="mailto:nginx@nginx.org" target="_blank">nginx@nginx.org</a><br>
<a href="http://mailman.nginx.org/mailman/listinfo/nginx" rel="noreferrer" target="_blank">http://mailman.nginx.org/mailm<wbr>an/listinfo/nginx</a><br>
</div>
</div>
</blockquote>
</div>
<br>
<br clear="all">
<br>
-- <br>
<div class="gmail-m_4983239477093541800gmail_signature">Regards,<br>
Ajay<br>
</div>
</div>
</div>
</div>
</div>
</blockquote>
</span></span>
</body>
</html>