This has come up a few times on SO but none of the solutions have worked. This is what I currently have:
location / {
try_files $uri $uri/ $uri.php;
}
location @php {
default_type application/x-httpd-php;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_param QUERY_STRING $args;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
location ~ \.php$ {
#fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_param QUERY_STRING $args;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
This example contains two options. First, the first stanza is written to push URL/foo.php and URL/foo through the final location stanza. If I replace the $uri.php in the try_files of the first stanza with @php, it should then use the @php location for URL/foo.
For the @php location I have tried to set SCRIPT_FILENAME to:
fastcgi_param SCRIPT_FILENAME "/usr/share/nginx/html$uri.php";
fastcgi_param SCRIPT_FILENAME "$request_filename.php";
None of these have worked.
In debugging this, no add_header line has ever emitted anything for URL/foo. The Content-Type is always set to application/octet-stream and, amusingly, it always manages to send back the content of the php file (it gets downloaded).
I'm obviously doing something wrong, but I'm not seeing what.