2

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.

1
  • @MichaelHampton Hi, I have checked file permissions, ownership, limit extenstions, error/access logs, different location ~ \.(php|php5)$ directives, different nginx config setups, but nothing. I got every time errors for example 206, 304, 403 or just getting file to be downloaded (not parsed). Any idea what should I check?
    – Bex1977
    Feb 28, 2014 at 15:30

1 Answer 1

4

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;
6
  • I have tried the same :\ and I have even tried to copy the same \.php$ code and just to add the php5. I got this kind of errors (access denied): 2014/02/28 14:42:06 [error] 11553#0: *13 FastCGI sent in stderr: "Access to the script '/var/www/site.com/web/sitemap.php5' has been denied (see security.limit_extensions)" while reading response header from upstream, client: 38.104.50.241, server: site.com, request: "GET /sitemap.php5 HTTP/1.1", upstream: "fastcgi://127.0.0.1:9048", host: "www.site.com", referrer: "site.com"
    – Bex1977
    Feb 28, 2014 at 15:24
  • p.s. After every change I restart php5-fpm and nginx to be sure..but still no progress
    – Bex1977
    Feb 28, 2014 at 15:25
  • THANK YOU @quadruplebucky!!! I am so happy :) it works now when I added fastcgi_pass unix:/var/run/php5-fpm.sock; you are king!
    – Bex1977
    Feb 28, 2014 at 16:38
  • the reason that works is because fastcgi_param (environment vars) don't survive "outside" (on the network) but are preserved when php-fpm accesses a local unix socket. Feb 28, 2014 at 16:41
  • @quadruplebucky, I have same problem. I have raised a question here. can you please look once. stackoverflow.com/questions/33409539/… Oct 30, 2015 at 12:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .