Location regex

Marcus Clyne maccaday at gmail.com
Wed Oct 28 03:56:03 MSK 2009


Mathew Davies wrote:
> Hi.
>
> I am having trouble with a location regular expression.
>
>     location ~* ^/(library|conf|appg) {
>       return 403;
>     }
>
A more efficient way of doing this is :

location ^~ /library {
    return   403;
}

location ^~ /conf {
    return   403;
}

location ^~ /appg {
    return   403;
}

since it checks the URLs using string comparison (rather than regexes) 
and will halt location-searching immediately if it matches one of the 
above locations.


>
> It is my understanding the following regular expression should match 
> any uri starting with library, conf or appg. However, this is not the 
> case.
>
> For instance.
>
>     http://domain.com/appg/
>
>
> will match fine where as
>
>     http://domain.com/appg/.file
>
>
> wont match (causing the file to be downloaded)
>
> Am I doing something inherently wrong or is this a bug in Nginx?
There's probably some other location directive in your conf that is 
matching http://domain.com/appg/.file.  If you don't want to use the 
more efficient, static locations above, try posting your full conf file.

Marcus.





More information about the nginx mailing list