NGINX doesn’t parse .php5 as .php

nginxphp-fpm

I have installed nginx with ISPconfig. Everything works fine except some websites I have ported from apache server unfortunately have .php5 extension and I don't know how to make nginx to parse them. I have tried many solutions and variations, but still can't make it work.

I will paste my settings from files, and if someone had similar experience that want to share, I would be thankful.

Part of settings from files:
/etc/php5/fpm/php.ini

cgi.fix_pathinfo=0

/etc/nginx/sites-available/default

server {
        listen 80 default_server;
        root /usr/share/nginx/html;
        index index.html index.php index.htm;
        location / {
                try_files $uri $uri/ /index.html;
        }
}
location ~ \.php$ {
        #       fastcgi_split_path_info ^(.+\.php)(/.+)$;
        #       # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
        #
        #       # With php5-cgi alone:
        #       fastcgi_pass 127.0.0.1:9000;
        #       # With php5-fpm:
        #       fastcgi_pass unix:/var/run/php5-fpm.sock;
        #       fastcgi_index index.php;
        #       fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        #       include fastcgi_params;
                try_files $uri =404;
                fastcgi_pass unix:/var/run/php5-fpm.sock;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include fastcgi_params;
        }

Vhost configuration file for specific domain that has error:

      location ~ \.php$ {
            try_files /58c4be432bbd2af65343c142b9ec45ec.htm @php;
        }


        location @php {
            try_files $uri =404;
            include /etc/nginx/fastcgi_params;
            fastcgi_pass 127.0.0.1:9048;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            fastcgi_intercept_errors on;
        }

        location / {
                try_files $uri $uri/ /index.php?q=$uri&$args;
        }

/etc/php5/fpm/pool.d/www.conf has unCommented:

security.limit_extensions = .php .php3 .php4 .php5

And when someone access that .php5 page (website has over 500 backlinks to them) browser starting to download, like php-fpm is not parsing .php5 file:

XX.XXX.X.XXX - - [26/Feb/2014:22:53:07 +0000] "GET /sitemap.php5 HTTP/1.1" 304 0 "-" "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.117 Safari/537.36"
XX.XXX.XX.XXX - - [26/Feb/2014:22:54:27 +0000] "GET /index.php5 HTTP/1.1" 200 71941 "-" "Mozilla/5.0 (Windows NT 6.3; WOW64; rv:27.0) Gecko/20100101 Firefox/27.0"
XX.XXX.X.XXX - - [26/Feb/2014:22:56:43 +0000] "GET /sitemap.php5 HTTP/1.1" 200 71941 "-" "Mozilla/5.0 (Windows NT 6.3; WOW64; rv:27.0) Gecko/20100101 Firefox/27.0"

How can I setup nginx to parse .php5 pages like .php?

Thank you in advance.

Best Answer

If you make every line with:

      location ~ \.php$ {

look like:

      location ~ \.(php|php5)$ {

It should do what you want. Leave the @php lines alone (@php is an internal block). That regex could be shorter of course but it would be less clear.

ALSO:

In your location @php block pass to the socket instead of localhost:

      fastcgi_pass unix:/var/run/php5-fpm.sock;