URL-Rewriting not working

Ajay Garg ajaygargnsit at gmail.com
Mon Apr 10 04:53:42 UTC 2017


Thanks a ton Lucas .. moved to map :)

Thanks a ton again !!!



Thanks and Regards,
Ajay

On Sun, Apr 9, 2017 at 9:17 PM, Lucas Rolff <lucas at lucasrolff.com> wrote:

> In general try to avoid using the if directive too much.
> https://www.nginx.com/resources/wiki/start/topics/depth/ifisevil/
>
> 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
>
> From: nginx <nginx-bounces at nginx.org> on behalf of Ajay Garg <
> ajaygargnsit at gmail.com>
> Reply-To: "nginx at nginx.org" <nginx at nginx.org>
> Date: Sunday, 9 April 2017 at 17.37
> To: "nginx at nginx.org" <nginx at nginx.org>
> Subject: Re: URL-Rewriting not working
>
> 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
>
>
> _______________________________________________
> 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/20170410/3616061d/attachment-0001.html>


More information about the nginx mailing list