Location regex
Igor Sysoev
is at rambler-co.ru
Wed Oct 28 10:27:25 MSK 2009
On Wed, Oct 28, 2009 at 01:37:04AM +0000, Mathew Davies wrote:
> >
> > A more efficient way of doing this is :
> >
>
> I do not see why. I am specifying "return 403" 3 times vs once. I was it
> doing it this way before and did not think it was so efficient.
>
> Here is my full config
>
> server {
> > listen 80;
> > server_name ---;
> > root /home/website/www/---/public/;
> > index index.php index.html index.htm;
> >
> > # Logs
> > access_log /home/website/www/---/log/access.log combined;
> > error_log /home/website/www/---/log/error.log warn;
> >
> > # Protect certain directories.
> > location ~* ^/(library|conf|appg) {
> > return 403;
> > }
> >
> > # Cache forum assets for as long as possible.
> > location ~* \.(css|js|gif|ico)$ {
> > expires max;
> > add_header Cache-Control private;
> > break;
> > }
> >
> > location ~* \.php$ {
> > fastcgi_pass 127.0.0.1:9000;
> > fastcgi_index index.php;
> > fastcgi_param SCRIPT_FILENAME
> > $document_root$fastcgi_script_name;
> > include fastcgi_params;
> > }
> > }
> >
In this configuration http://domain.com/appg/.file should be handled by
location ~* ^/(library|conf|appg) {
Could you create debug of the request ?
> Thank you for the quick response.
>
> 2009/10/28 Marcus Clyne <maccaday at gmail.com>
>
> > 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.
> >
> >
--
Igor Sysoev
http://sysoev.ru/en/
More information about the nginx
mailing list