PHP below server root not served

Francis Daly francis at
Tue Jan 14 22:12:52 UTC 2014

On Sun, Jan 12, 2014 at 09:27:23PM +1100, nano wrote:
> On 11/01/2014 2:34 AM, Francis Daly wrote:
> >>On 10/01/2014 8:36 PM, Francis Daly wrote:
> >>>>On 10/01/2014 7:58 AM, Francis Daly wrote:

Hi there,

> >>>>>   location ^~ /phpmyadmin/ {
> >>>>>     location ~ \.php$ {
> >>>
> >>>At this point, you could instead use "location ~
> >>>^/phpmyadmin/.*\.php$". It will match exactly the same requests --
> >>>can you see why?

> Another presumption on my part, however, where is the nginx regex 
> documentation? I cannot seem to find it or even what syntax nginx uses. 

I don't think I've ever looked for nginx regex documentation. I think
I've always just used "normal" regex characters, and they worked.

It's not difficult to test. Example below.

One thing that was not immediately obvious to me from the documentation,
was that the whitespace separating the uri from the modifier in the
location directive is optional. But it shows up pretty quickly in testing
(and is clear from the "real" documentation, which is in the directory
marked "src").

So: knowing that, it may make it easier to interpret other people's
config files.

> Also, what is the answer, I still cannot figure it out?

Which requests would match the original top-level prefix location?

Of those, which would match the first suggested nested regex location? And
which would match the second suggested nested regex location?

Are there any that would match only one of the two suggested nested
regex locations? If so, they don't match exactly the same requests.

> Thank you, Francis. I need to understand what each prefix and regex 
> character is and what it does.

Fair enough. There are four modifiers (plus "no modifier"; plus @,
which is separate).

> For example, the documentation is clear 
> that "^~" prefix will stop the search if it matches the request. 

Yes, that's one of the four modifiers.

> However, there is nothing regarding "~^".

That's not one of the four modifiers. It is one of the four modifiers
followed by something else. There's also nothing explicit regarding
"~A". Or "~\.".

(If it doesn't start with one of the modifiers, then it is "no modifier",
which means "prefix string". If *that* doesn't start with /, it is
unlikely to be useful.)

Could """nginx: [emerg] invalid location modifier "~^" in
/usr/local/nginx/conf/nginx.conf:29""" be made clearer? The only way
you won't get that is if you don't have a separate uri in the directive.

> This might help me better 
> construct my location blocks and ensure the correct location is used for 
> each request.

"starts with ~" means "it's a regex". Everything after the ~ is the
regex. Apart from one documented case which could not be a regex anyway.

If you have as your server block the following:

    server {
      listen       8888;
      location / { return 200 "location / \n"; }
      location ~A { return 200 "location ~A \n"; }
      location ~ \. { return 200 "location ~ \. \n"; }
      location = / { return 200 "location = / \n"; }

Then can you predict the response to each of:

  curl http://localhost:8888/path
  curl http://localhost:8888/
  curl http://localhost:8888/A.A

Add your sample locations, make your sample requests, understand why
each location was chosen each time.



to the "events{}" block if you want to see lots more in the error log.

Good luck with it,

Francis Daly        francis at

More information about the nginx mailing list