Nginx downloading PHP file only if .php is in the URL

Solution 1:

If this is sometimes working (so you know PHP-FPM is up and working), I'd be pretty set on this being a nginx issue. I'm suspicious of a couple of the rules in your PHP location block. They might be breaking in certain URLs causing nginx to dump out.

You only need 2 lines for catching directory indexes:

location ~ \.php$ {
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    include fastcgi_params;
}

Strip that location back to that, reload nginx and see what happens.

If you need rewriting (pretty URLs in Wordpress, etc) you want to add something like this

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

But only do that once you've got standard URLs working.

Solution 2:

Had this same problem, however, i also needed this line

include fastcgi.conf;

I also had

location ~* .+ {..}

and had to make sure it went after location ~ \.php$ {..}