3

I have this configuration of nginx + phpfpm + phpmyadmin:

root /var/www/utils;

location ~ ^/phpmyadmin/.*\.(jpg|jpeg|gif|png|css|js|ico)$ {
    root           /var/www/utils;
}

location = /phpmyadmin {
    index index.php;
}

location ~ ^/phpmyadmin.*(\.php|)$ {
    index          index.php;
    fastcgi_index  index.php;
    fastcgi_pass   unix:/var/run/php5-fpm.sock;
    fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    include        fastcgi_params;
}

All is good, but if I remove "location = /phpmyadmin", I get 403 error on _http://server/phpmyadmin.

How can I access to the ALL subdirectories such as _http://server/phpmyadmin/setup ?

I get "Access to the script '/var/www/utils/phpmyadmin/setup' has been denied - on every directory without slash at the end, if I haven't written a special config for an each one.

xwild
  • 1,114
  • 2
  • 9
  • 25

1 Answers1

1

As stated in nginx documentation:

$fastcgi_script_name variable takes value of incoming request URI, and in case URI is finished by a slash, then $fastcgi_script_name is appended with what is defined with fastcgi_index directive.

So if your request is "/phpmyadmin/setup/" and fastcgi_index is set to "index.php", then $fastcgi_script_name variable will be "/phpmyadmin/setup/index.php". Therefore $document_root plus $fastcgi_script_name will be "/var/www/utils/phpmyadmin/setup/index.php", which should work fine.

But if you make request like "/phpmyadmin/setup" (without slash at the end), then $fastcgi_script_name will not be appended by fastcgi_index, i.e. it would be just "/phpmyadmin/setup". And $document_root plus $fastcgi_script_name will be "/var/www/utils/phpmyadmin/setup", which won't work since there is not such file.

You should either use URIs with slashes, or define a rewrite rule (in a "server" block of configuration), which will be adding slash to the URIs that do not end with some extension (so that URIs like "/phpmyadmin/myscript.php" won't transformed into "/phpmyadmin/myscript.php/". It should be like:

rewrite ^([^\.]*[^\/])$ $1/ break;

Did not test that myself, though.

kernel
  • 164
  • 3