# Bug in if?

**URL:** <https://www.ruby-forum.com/t/bug-in-if/195345>\
**Category:** NGINX\
**Created:** [September 21, 2010, 11:58pm UTC](https://www.ruby-forum.com/t/bug-in-if/195345 "2010-09-21T23:58:59Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Marcin\_SWMPSS\_Janow](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/a88e4f/32.png) [@Marcin\_SWMPSS\_Janow](https://www.ruby-forum.com/u/Marcin_SWMPSS_Janow)\
**Post date:** [September 21, 2010, 11:58pm UTC](https://www.ruby-forum.com/t/bug-in-if/195345/1 "2010-09-21T23:58:59Z")

</div>

Hello,

I’m running a small shell server for me and my friends and would like  
every user to have his own [example.com/user](http://example.com/user) web-accessible,  
password-protected directory not available to other users. Preferably,  
with authentication against PAM so that one password could be used for  
all services.

Currently, this is the configuration I came up with (no PAM  
authentication yet):

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;  
Â Â Â Â }

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”

And this is debug.log: [http://pastebin.com/4wUQkXZH](http://pastebin.com/4wUQkXZH)

Nginx was compiled with the following options:

–conf-path=/etc/nginx/nginx.conf --pid-path=/var/run/nginx.pid  
–lock-path=/var/lock/nginx.lock  
–http-client-body-temp-path=/var/lib/nginx/body  
–http-proxy-temp-path=/var/lib/nginx/proxy  
–http-fastcgi-temp-path=/var/lib/nginx/fastcgi Â --with-debug  
–with-http\_stub\_status\_module --with-http\_flv\_module  
–with-http\_ssl\_module --with-http\_dav\_module  
–with-http\_gzip\_static\_module --with-http\_realip\_module --with-mail  
–with-mail\_ssl\_module --with-ipv6  
–add-module=/home/wmp/tmp/nginx/nginx-0.7.65/modules/nginx-upstream-fair  
–add-module=/home/wmp/tmp/nginx/nginx-0.7.65/modules/ngx\_http\_auth\_pam  
–with-perl=/usr/bin/perl --sbin-path=/usr/sbin  
–error-log-path=/var/log/nginx/error.log  
–http-log-path=/var/log/nginx/access.log --with-http\_perl\_module

wmp is, obviously, my username

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

I would like to thank kolbyjack from #nginx for his help with this  
problem so far.

–  
Marcin Janowski(WMP)

---

<div class="post-metadata">

**Author:** ![Marcin\_SWMPSS\_Janow](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/a88e4f/32.png) [@Marcin\_SWMPSS\_Janow](https://www.ruby-forum.com/u/Marcin_SWMPSS_Janow)\
**Post date:** [September 22, 2010, 4:06am UTC](https://www.ruby-forum.com/t/bug-in-if/195345/2 "2010-09-22T04:06:41Z")

</div>

Hello!

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

[…]

> š š š š š š š štypes { }  
> 87.205.146.217, server: domain, request: “GET /wmp/download/  
> HTTP/1.1”, host: “domain:9900”

> **[GitHub - nginxinc/nginx-wiki: ARCHIVED -- Source for the now archived NGINX Wiki...](https://github.com/nginxinc/nginx-wiki)**
>
> ARCHIVED -- Source for the now archived NGINX Wiki section of https://www.nginx.com

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 D.

---

<div class="post-metadata">

**Author:** ![Marcin\_SWMPSS\_Janow](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/a88e4f/32.png) [@Marcin\_SWMPSS\_Janow](https://www.ruby-forum.com/u/Marcin_SWMPSS_Janow)\
**Post date:** [September 22, 2010, 10:38am UTC](https://www.ruby-forum.com/t/bug-in-if/195345/3 "2010-09-22T10:38:17Z")

</div>

2010/9/22 Maxim D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> > location ~ ^/(.+?)/download(/._) Â {  
> > Â Â Â Â }  
> > See if-and-alias example.  
> > Ok, i do:  
> > location ~ ^/(?.+?)/download(?/._) {  
> > alias /home/$user/rtorrent/download$file;

but down work, i have this same error.

–  
Marcin Janowski(WMP)

---

<div class="post-metadata">

**Author:** ![Marcin\_SWMPSS\_Janow](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/a88e4f/32.png) [@Marcin\_SWMPSS\_Janow](https://www.ruby-forum.com/u/Marcin_SWMPSS_Janow)\
**Post date:** [September 22, 2010, 10:54am UTC](https://www.ruby-forum.com/t/bug-in-if/195345/4 "2010-09-22T10:54:41Z")

</div>

Hello!

On Wed, Sep 22, 2010 at 10:36:59AM +0200, Marcin WMP Janowski wrote:

> > > š š š š š š š šif ($hack = ab) { return 403; }
> > 
> > See if-and-alias example.
> 
> Ok, i do:  
> location ~ ^/(?.+?)/download(?/.\*) {  
> alias /home/$user/rtorrent/download$file;
> 
> but down work, i have this same error.

Nobody said using named captures will help. Use root instead.

Maxim D.

---

<div class="post-metadata">

**Author:** ![Marcin\_SWMPSS\_Janow](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/a88e4f/32.png) [@Marcin\_SWMPSS\_Janow](https://www.ruby-forum.com/u/Marcin_SWMPSS_Janow)\
**Post date:** [September 22, 2010, 4:13pm UTC](https://www.ruby-forum.com/t/bug-in-if/195345/5 "2010-09-22T16:13:15Z")

</div>

I cant use root, becouse in code what i send you i have simple path. In  
real  
i have few directory in path
