URL-Rewriting not working

Ajay Garg ajaygargnsit at gmail.com
Sun Apr 9 15:37:02 UTC 2017


Hi Francis.

On Sun, Apr 9, 2017 at 8:47 PM, Francis Daly <francis at daoine.org> wrote:

> On Sun, Apr 09, 2017 at 06:36:51PM +0530, Ajay Garg wrote:
>
> Hi there,
>
> > Got it Francis !!
>
> Good news.
>
> >                 location / {
> >                                         auth_basic 'Restricted';
> >                                         auth_basic_user_file
> > /home/20da689b45c84f2b80bc84d651ed573f/.htpasswd;
> >
> >                                         if ($remote_user =
> > "20da689b45c84f2b80bc84d651ed573f") {
> >                                                 proxy_pass
> > https://127.0.0.1:2000;
> >                                         }
> >
> >                 }
>
> When you come to add the second user, you will see that you want one
> file with all the user/pass details.
>


Yes, I have already changed it to use just one file.
Upon that, would not just multiple sections of "if" checks for $remote_user
suffice, something like ::

#########################################################################
server {
                listen 2000 ssl;

                ssl_certificate /etc/nginx/ssl/nginx.crt;
                ssl_certificate_key /etc/nginx/ssl/nginx.key;

                location / {
                                        auth_basic 'Restricted';
                                        auth_basic_user_file
/etc/nginx/ssl/.htpasswd;

                                        if ($remote_user =  "user1") {
                                                proxy_pass
https://127.0.0.1:2001 <https://127.0.0.1:2000>;
                                        }

                                        if ($remote_user =  "user2") {
                                                proxy_pass
https://127.0.0.1:2002 <https://127.0.0.1:2000>;
                                        }

                                       # and so on ....

                }
         }
#########################################################################

Looking forward to hearing back from you.


Thanks and Regards,
Ajay




>
> You will probably also see that it will be good to use a map
> (http://nginx.org/r/map) to set a variable for the port to connect to,
> based on $remote_user. Then your main config becomes just "proxy_pass
> http://127.0.0.1:$per_user_port;".
>
> Note that I have not tested that, and expect that there may be some more
> subtleties involved, such as perhaps requiring an explicit proxy_redirect
> directive.
>
> Note also that you will probably want to set a default value for
> $per_user_port, and make sure that something sensible happens when that
> value is used -- probably a response along the lines of "something isn't
> fully set up on the server yet; please wait or let us know", so the user
> is not confused.
>
> Good luck with it,
>
>         f
> --
> Francis Daly        francis at daoine.org
> _______________________________________________
> nginx mailing list
> nginx at nginx.org
> http://mailman.nginx.org/mailman/listinfo/nginx
>



-- 
Regards,
Ajay
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx/attachments/20170409/09c1a18b/attachment.html>


More information about the nginx mailing list