PHP below server root not served

nano nanotek at
Fri Jan 10 09:37:36 UTC 2014

On 10/01/2014 7:58 AM, Francis Daly wrote:
> The suggestion is along the lines of:
>    location ^~ /phpmyadmin/ {
>      location ~ \.php$ {
>        # config for php scripts to be fastcgi_pass'd elsewhere
>      }
>      # config for static files to be served directly
>    }
> and then whatever other top-level location{} blocks that you want for
> the rest of the server config -- possibly include a "location /" and a
> "location ~ \.php$".

I have done some extensive testing, using the suggestions you and Jim 
provided. In summary, the nesting of "location ~ \.php$" inside 
"location ^~ /phpmyadmin/" does not work. The error logged is:

[error] 50038#0: *7541 FastCGI sent in stderr: "Primary script unknown" 
while reading response header from upstream, client: clientIP, server:, request: "GET /phpMyAdmin/ HTTP/1.1", upstream: 
"fastcgi://unix:/var/run/php-fpm.sock:", host: ""

No matter what variation I tried[0], that was the repeated result.

However, the nesting of "~ ^/phpMyAdmin/(.*\.php)$" inside "location ^~ 
/phpmyadmin/" does work. With everything else the same, this regular 
expression works. See the current working configuration, making use of 
your nesting advice:

location ^~ /phpmyadmin {
         access_log  off;
         rewrite ^  /phpMyAdmin/ permanent;

location /phpMyAdmin {
         root /usr/local/www;
         index index.php index.html;

                 location ~ ^/phpMyAdmin/(.*\.php)$ {
                         root /usr/local/www/;
                         include conf.d/php-fpm;

The included php-fpm[1] file is provided below.

I do not know why your suggested regular expression does not work; 
however, your advice to nest does work. Thank you very much for your 
repeated efforts to help, it is very much appreciated.

I am interested as to why this is more efficient and considered better 
practice than my former configuration[2]? Why the statement: 
"DoNotUseAlias (unless necessary)"? My original working setup[2] got the 
job done with only two location blocks. Your recommendations require 
three and a rewrite. Does this not create more work for the server as 
well as more lines of configuration?

Francis, Jim; thank you both very much for your help.

[0] example variations of your suggestions:

[1] conf.d/php-fpm:

location /phpmyadmin {
	alias /usr/local/www/phpMyAdmin/;
	index index.php index.html;

location ~ ^/phpmyadmin/(.*\.php)$ {
	root /usr/local/www/phpMyAdmin/;
	fastcgi_pass unix:/var/run/php-fpm.sock;
	include fastcgi_params;
	fastcgi_param SCRIPT_FILENAME /usr/local/www/phpMyAdmin/$1;

-- <- for dummies

More information about the nginx mailing list