# Alias, regex and try\_files am i doing it wrong, or is this a bug?

**URL:** <https://www.ruby-forum.com/t/alias-regex-and-try-files-am-i-doing-it-wrong-or-is-this-a-bug/215705>\
**Category:** NGINX\
**Created:** [January 13, 2012, 5:37am UTC](https://www.ruby-forum.com/t/alias-regex-and-try-files-am-i-doing-it-wrong-or-is-this-a-bug/215705 "2012-01-13T05:37:07Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [January 13, 2012, 5:37am UTC](https://www.ruby-forum.com/t/alias-regex-and-try-files-am-i-doing-it-wrong-or-is-this-a-bug/215705/1 "2012-01-13T05:37:07Z")

</div>

Ok, i was trying to do drupal as a subdirectory on my site, but i’ve hit  
a problem and I think its a bug. Im using 10.04 ubuntu, the nginx ppa  
with 1.0.11 nginx.

If i have the following config’s and i try to retrieve the file  
[http://mysite/drupal/somefile:](http://mysite/drupal/somefile:)

location ~ /drupal(.\*) {  
index index.php;  
alias /local\_config/$1;  
try\_files $uri @drupalrewrite;  
}

The file nginx is apparently trying retrieve  
“/local\_config//somefile/drupal/somefile” rather then  
“/local\_config//somefile”, which leads me to believe $uri isnt being set  
correctly by nginx.

If instead, i have this as a config:

location /drupal/ {  
index index.php;  
alias /local\_config/;  
try\_files $uri @drupalrewrite;  
}

it does the right thing, and try files will attempt to get  
“/local\_config/somefile”, so im really confused as to why it happens.  
Either im doing something wrong or in the first example, $uri gets set  
incorrectly? some small chunks of debug output to show what i mean:

From the first config:  
2012/01/13 04:03:18 [debug] 22504#0: \*4 http request line: “GET  
/drupal/somefile HTTP/1.1”  
2012/01/13 04:03:18 [debug] 22504#0: \*4 http uri: “/drupal/somefile”  
2012/01/13 04:03:18 [debug] 22504#0: \*4 http args: “”  
…  
2012/01/13 04:03:18 [debug] 22504#0: _4 using configuration  
"/drupal(._)"  
…  
2012/01/13 04:03:18 [debug] 22504#0: \*4 trying to use file:  
“/drupal/somefile” “/local\_config//somefile/drupal/somefile” ← path  
looks incorrect?

From the second config:  
2012/01/13 04:26:58 [debug] 23019#0: \*1 http request line: “GET  
/drupal/somefile HTTP/1.1”  
2012/01/13 04:26:58 [debug] 23019#0: \*1 http uri: “/drupal/somefile”  
…  
2012/01/13 04:26:58 [debug] 23019#0: \*1 using configuration “/drupal/”  
…  
2012/01/13 04:26:58 [debug] 23019#0: \*1 trying to use file: “somefile”  
“/local\_config/somefile” \<— correct

Posted at Nginx Forum:

> **[alias, regex and try\_files am i doing it wrong, or is this a bug?](https://forum.nginx.org/read.php?2,221138,221138#msg-221138)**
>
> Ok, i was trying to do drupal as a subdirectory on my site, but i've hit a problem and I think its a bug. Im using 10.04 ubuntu, the nginx ppa with 1.0.11 nginx. If i have the following config's and i try to retrieve the file...

---

<div class="post-metadata">

**Author:** ![takigama](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/96bed5/32.png) [@takigama](https://www.ruby-forum.com/u/takigama)\
**Post date:** [January 16, 2012, 7:38am UTC](https://www.ruby-forum.com/t/alias-regex-and-try-files-am-i-doing-it-wrong-or-is-this-a-bug/215705/2 "2012-01-16T07:38:12Z")

</div>

## Maxim D. Wrote:

> > The file nginx is apparently trying retrieve  
> > think that behaviour of try\_files with alias in a  
> > regexp location  
> > is inherently undefined, but the example above  
> > should certainly  
> > work as expected.)

Thanks for confirming, was driving me a little nuts trying to work out  
why it was coming up with the paths it was using.

Regards

Posted at Nginx Forum:  
[http://forum.nginx.org/read.php?2,221138,221283#msg-221283](http://forum.nginx.org/read.php?2,221138,221283#msg-221283)

---

<div class="post-metadata">

**Author:** ![takigama](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/96bed5/32.png) [@takigama](https://www.ruby-forum.com/u/takigama)\
**Post date:** [January 13, 2012, 1:52pm UTC](https://www.ruby-forum.com/t/alias-regex-and-try-files-am-i-doing-it-wrong-or-is-this-a-bug/215705/3 "2012-01-13T13:52:36Z")

</div>

Hello!

On Thu, Jan 12, 2012 at 11:36:41PM -0500, takigama wrote:

> ```
> try_files $uri @drupalrewrite;
> 
> ```
> 
> }
> 
> The file nginx is apparently trying retrieve  
> “/local\_config//somefile/drupal/somefile” rather then  
> “/local\_config//somefile”, which leads me to believe $uri isnt being set  
> correctly by nginx.

Yes, this looks like a bug for me.

(Internally, the problem is a bit complex, and I event tend to  
think that behaviour of try\_files with alias in a regexp location  
is inherently undefined, but the example above should certainly  
work as expected.)

> If instead, i have this as a config:
> 
> location /drupal/ {  
> index index.php;  
> alias /local\_config/;  
> try\_files $uri @drupalrewrite;  
> }
> 
> it does the right thing, and try files will attempt to get  
> “/local\_config/somefile”, so im really confused as to why it happens.

This works as expected.

The difference is that in a regexp location the “alias” directive  
specifies full path to a file to use, and try\_files isn’t  
currently able to handle this.

Maxim D.
