Welcome! Log In Create A New Profile

Advanced

Re: Location regex + if + basic auth to restrict directory access

B.R.
March 10, 2013 05:32AM
I'll answer to my own question there:

Apparently, yes, evaluating something with the 'if' directive doesn't
propagate the environment containing the variables from the 'location'
directive.
All explained on
StackOverflowhttp://stackoverflow.com/questions/10876252/nginx-given-custom-subdomain-location-regex-matching-with-http-user-agent-con
..

The *incorrect* way:

location ^~ /documents/(\w+) {
if ($1 != $remote_user) {
return 503;
}
}
*--> $1 variable is unknown*

The *correct* way:
location ^~ /documents/(\w+) {
set $user $1;
if ($user != $remote_user) {
return 503;
}
}

Although the syntax is now OK and the configuration is able to be reloaded,
it doesn't seem to work at all...

When connecting with the user 'abc', I am still able to access
/documents/def/mydoc.txt.
What's wrong with my way of restricting access?

Thanks for any help,
---
*B. R.*


On Thu, Feb 28, 2013 at 5:36 PM, B.R. <reallfqq-nginx@yahoo.fr> wrote:

> Hello,
>
> I am using basic auth + $remote_user variable send to the back-end
> application to change context depending on the logged-in user.
>
> The thing is, even if the page rendered by the back-end uses nginx user
> authentication, resources from a directory are still allowed for everyone.
>
> My 'documents' directory is sorted as follows:
> documents/
> abc/ --> stores content for user 'abc'
> def/ --> stores content for user 'def'
> ...
>
> I tried the following:
> location ^~ /documents/(\w+) {
> if ($1 != $remote_user) {
> return 503;
> }
> }
>
> But Nginx refuses to validate configuration:
> nginx: [emerg] unknown "1" variable
> nginx: configuration file /etc/nginx/nginx.conf test failed
>
> Does the 'if' directive have an environment isolated for the on of the
> 'location' directive?
> Am I using wrong syntax?
> Is there a 'IfIsEvil' case corresponding to my needs to avoid the use of
> the 'if' directive?
>
> Thanks,
> ---
> *B. R.*
>
_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Subject Author Posted

Location regex + if + basic auth to restrict directory access

B.R. February 28, 2013 05:38PM

Re: Location regex + if + basic auth to restrict directory access

B.R. March 10, 2013 05:32AM

Re: Location regex + if + basic auth to restrict directory access

Francis Daly March 10, 2013 06:48AM

Re: Location regex + if + basic auth to restrict directory access

B.R. March 10, 2013 03:16PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 139
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready