PHP below server root not served

B.R. reallfqq-nginx at
Thu Jan 9 12:57:32 UTC 2014

 Try to understand what you are doing first.

 One request is handled in one location.
>> For this request, the one location that you want to be used is not the
>> one that nginx actually uses.
>>> ​1. ​
>>> location / {
>>> ​2. ​
>>> location ~ \.php$ {
>>> ​3. ​
>>> location /phpmyadmin/ {
>>> ​4. ​
>>> location ~ ^/phpmyadmin/(.*\.php)$ {
>> A request for /phpmyadmin/index.php will be handled in the second location
>> above, not the fourth.
​The docs say 'To find location matching a given request, nginx first
checks locations defined using the prefix strings (prefix locations). Among
them, the location with the longest matching prefix is selected and
remembered. Then regular expressions are checked, in the order of their
appearance in the configuration file. The search of regular expressions
terminates on the first match, and the corresponding configuration is used.
If no match with a regular expression is found then the configuration of
the prefix location remembered earlier is used.'

Thus, in your configuration, for a '/phpmyadmin/***.php' request, it does
the following:
* Start searching prefix location *
1. location /
3. location /phpmyadmin/
* End of prefix location search, longest prefix = 3. *

* Start searching regex expressions
2. location ~\.php$ // First regex found, stop of search
* End of prefix location search, regex found is being used * // Otherwise,
if no matching regex were to be found, a fallback to the longest prefix
location found before would have applied

Your problem is that the location 4. is *never* used, because the regex
being used is the first which matches. Your generic '\.php$' will catch'em

​Francis provided 2 ways of fixing your problem:
I. Re-arranging your config file so 'location /phpmyadmin/(.*\.php)$' is
found *before* \.php$​

On Thu, Jan 9, 2014 at 1:41 PM, nano <nanotek at> wrote:

> Admittedly, I don't know *why* what I changed fixed the problem, but it
> did. I relocated the phpMyAdmin entries to above the "location /" block
> from beneath the "location /" block.
> ​* snip *
> The syntax is identical, just those two location blocks are in a different
> place. I would like to know why this works, but am just happy that it does.
> I look forward to better understanding this great program.

You did just that...

II. Use a smarter (and more scalable, in light of future adds to the nginx
config) way, which is nesting the rules of 'location
/phpmyadmin/(.*\.php)$' in a 'location ~\.php$' block embedded in a
'location ^~ /phpmyadmin/' block.

Note the modification made to the prefix block for phpmyadmin. The docs say
'If the longest matching prefix location has the “^~” modifier then regular
expressions are not checked.'
This way, longest prefix will be 'location /phpmyadmin/' *but the generic
'location \.php$' won't be used* since there will be no regex search.

Hope I helped,
*B. R.*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the nginx mailing list