[0.8.50] Bug in if?

Maxim Dounin mdounin at mdounin.ru
Wed Sep 22 06:06:00 MSD 2010


Hello!

On Tue, Sep 21, 2010 at 11:57:33PM +0200, Marcin WMP Janowski wrote:

[...]

> and it works as expected. Now, I tried to separate users' access (so
> that any given user had access only to his directory) with the if
> statements:
> 
> location ~ ^/(.+?)/download(/.*)  {
>                auth_basic            "Restricted";
>                auth_basic_user_file  /etc/nginx/htpasswd;
>                alias /home/$1/download$2;
>                autoindex on;
>                include mime.types;
>                types { }
>                default_type application/octet-stream;
>                if ($remote_user != '') { set $hack b; }
>                if ($remote_user != $1) { set $hack a$hack; }
>                if ($hack = ab) { return 403; }
>        }
> 
> That caused 404 errors. This is the relevant fragment of the error log:
> 
> 2010/09/21 23:12:41 [error] 31813#0: *245 "/home/wmp/download/.1
> Hostindex.html" is not found (2: No such file or directory), client:
> 87.205.146.217, server: domain, request: "GET /wmp/download/
> HTTP/1.1", host: "domain:9900"

http://wiki.nginx.org/IfIsEvil

See if-and-alias example.

[...]

> Is what I'm trying to do even possible? If so, how?

As far as I see

    root /home;

will to the same thing you are trying to do with alias.  Use it 
instead.

An alternative would be to move "if ... { set ... }" blocks to 
server level, but it's not needed here.

Maxim Dounin



More information about the nginx mailing list