The location behaviour in 0.7 - bug or feature?

Roxis roxis at list.ru
Fri Jul 11 01:35:57 MSD 2008


On Thursday 10 July 2008, Georgi Hristozov wrote:
> Hello,
> I'm happily using nginx 0.6 as a proxy to my Apache server. Nginx is
> serving the static content and Apache is doing the complicated work.
> I've been using  rules like this to proxy the requests:
>
> location ~ \.php$ {
> 	proxy_pass   http://ip:port;
> }
> location ~ /$ {
> 	proxy_pass   http://ip:port;
> }
>
> Obviously the first one redirects all requests to php scripts to the
> Apache daemon. The second one is in order to show the fancy Apache
> directory listings. Additionally, some directories should not be listed
> and it is defined in their respective .htaccess files, so I can't serve
> requests ending with / using nginx. The second "location" block
> guarantees that the .htaccess files will be respected (served by
> Apache), at least when directory listings are generated.
> This configuration worked ok for months until I tried to upgrade to the
> dev branch of nginx. I tried not to touch my config files. One of my
> virtual hosts uses fancy indexing for showing its structure and when I
> tried http://the.host/ I was surprised to get a 403 error from nginx.
> The request to / wasn't passed to Apache at all. The 0.6 version had
> done it until that moment. The request to http://the.host/directory/ hit
> Apache and I got the desired fancy index, it seemed that the problem is
> only with /. I added the following lines to all of my vhosts in the
> nginx.conf file:
>
> location = / {
> 	proxy_pass   http://ip:port;
> }
>
> And now 0.7 works like a charm.
> Now the question - shouldn't "location ~ /$" match / aswell? And why it
> matches it in 0.6, but doesn't match it in the 0.7 branch? I traced it
> back to 0.7.0, it seems that the whole branch doesn't work with this
> "old" config from 0.6. Is it a bug or feature? :)
>
> Thanks in advance!

It's 0.7 branch feature  )
i try to explain:
if request has exact match with non regex location and location has no 
prefixes "=" and "~^" than search stops and regex locations aren't checked.

in 0.7 request "/" will match "location /" or "location = /"
but not "location ~ /$"





More information about the nginx mailing list