alias/try_files bug?

Maxim Dounin mdounin at mdounin.ru
Fri Feb 3 11:49:54 UTC 2012


Hello!

On Thu, Feb 02, 2012 at 04:17:53PM -0500, Brian Gernhardt wrote:

> My server is running Ubuntu 11.10.  I've replicated this bug 
> with both the nginx-light package (1.0.5) and nginx-1.0.10 
> (compiled via passenger).
> 
> Here's a shortened version of my site configuration: 
> 
> --- 8< ---
> 
> server {
>    location /forum/ {
>       alias /srv/www/forum/;
>       index index.php index.html index.htm;
> 
>       location ~ \.php$ {
>          # Try to stop bad PHP requests, as per wiki
>          try_files $uri =404;
> 
>          fastcgi_pass php;
>       }
>    }
> }
> 
> --- 8< ---
> 
> This configuration returns 404 for _all_ PHP requests, even for 
> files that exist.  (There is normally a "location /" block that 
> points to a CMS.  But removing it still has gives the same 
> error.)
> 
> If I remove the try_files, the forum works.  If I remove the 
> alias and use "root /srv/www" instead, it works.  Only when I 
> use try_files and alias does it fail.
> 
> This looks like a bug to me, but I'm not familiar enough with 
> the nginx source to track it down.

Yes, this is a bug in try_files, thank you for your report.  
Reduced test case is:

    # bug: request "/foo/test.gif" will try "/tmp//foo/test.gif"

    location /foo/ {
        alias /tmp/;
        location ~ gif {
            try_files $uri =405;
        }
    }

I've filled a ticket for try_files + alias problems to make sure 
it won't be lost:

http://trac.nginx.org/nginx/ticket/97

Maxim Dounin



More information about the nginx-devel mailing list