nginx rewrite PHP with no extension

I recently had to troubleshoot an issue while migrating from cherokee to nginx. This was a PHP application which had a shared set of common scripts , these where accessed by domain/common/file which in turn was translated into /vhosts/shared/common and this then included the necessary files.

After doing the rewrite for nginx,

location ^~ /common/ {
fastcgi_split_path_info ^(/common)(/?.+)$;
fastcgi_param SCRIPT_FILENAME /vhosts/shared/common$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_pass 127.0.0.1:9000;
include fastcgi_params;
}

nginx was simply returning access denied.

# curl http://localhost/common/file
Access denied.

Which is because the new file has no extension and PHP-FPM now defaults to only allow .php. This can be altered by editing security.limit_extensions in the php-fpm.conf (in this case /etc/php-fpm.d/daemon.conf) to allow the extensions you need. In this case we needed it to support files without extensions so setting security.limit_extensions to FALSE done the job,

security.limit_extensions = FALSE

Leave a Reply

Your email address will not be published. Required fields are marked *