Location regex

Hi.

I am having trouble with a location regular expression.

location ~* ^/(library|conf|appg) {

return 403;
}

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?

-Mathew

Mathew D. 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.

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.

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 {

    location ~* ^/(library|conf|appg) {
    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;
}
}

Thank you for the quick response.

2009/10/28 Marcus C. [email protected]

Mathew D. 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.
When referring to ‘efficient’ I’m talking about the speed at which the
statements are processed by Nginx. Sorry if that wasn’t clear.
access_log /home/website/www/—/log/access.log combined;
add_header Cache-Control private;
}

What’s the URL you’re having problems with and which location is it
matching too? Since all the locations are regexes, I would have thought
that they would be processed in order - though I’m not sure if they are
somehow re-ordered according to certain matching priorities (though I
doubt it).

Using

location ^~ /library {
return 403;
}

location ^~ /conf {
return 403;
}

location ^~ /appg {
return 403;
}

will guarantee that they are processed (and matching halted) before
processing any regexes though, which is probably a good reason to put
them in that format anyway (if you change the ordering of your regexes,
then this might change the location they are matched to).

Marcus.

On Wed, Oct 28, 2009 at 01:37:04AM +0000, Mathew D. wrote:

    listen 80;
            return 403;
            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 ?

I retested again this morning and it is working correctly. I assumed my
browser cached the request and gave me false results.

Thank you Marcus, Michal and Igor for your help.

2009/10/28 Igor S. [email protected]

On Wed, Oct 28, 2009 at 2:37 AM, Mathew D.
[email protected] wrote:

    }

try

location ~* ^/(library|conf|appg).*$ {
return 403;
}

if you are on linux “man 7 regex” should be a good starting reading
before you goo off goggling.

mk

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs