Everyone knows there are many nginx tutorials out there and I would like
to
know what’s the “modern way” when writing a php location block, I’m
doing
(nginx 1.1.:
location ~ .php$ {
try_files $uri =404;
include fastcgi_params;
fastcgi_pass unix:/var/run/php5-fpm/www-data.sock;
}
And it works pretty well. I quick tested phpinfo, drupal, joomla,
wordpress
and they all run correctly with SEF urls etc.
However, I often see the following directives being used, how
important/useful are they?
Or, in other words, where PHP scripts require PATH_INFO /
PATH_TRANSLATED environment variables to be set appropriately to the
request, such as shown above. It isn’t a popular practice these days,
though, because URLs can be something like:
/index.php/path/to/another/index.php/path…
So, adding
fastcgi_split_path_info ^(.+.php)(/.+)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
doesn’t really hurt.
The box I’m running does shared hosting for a couple of users and I
don’t
really know in advance what they want to install on their account.
I’m going to keep those 3 lines in hope it helps some php scripts out
there
to run correctly.
include fastcgi_params;
fastcgi_pass unix:/var/run/php5-fpm/www-data.sock;
}
This is a “generic” way. This way you don’t enumerate all the PHP
scripts
that are to be executed. The above is just the Nginx translation of
“default” Apache way.
There are better ways IMHO. But they require more effort to put in
place.
Also there’s no need to use fcgi_split_pathinfo even if your app uses
PATHINFO, like Chive for example. You can get the same employing named
captures with regex based locations.
Well, in that case you may as well support SCRIPT_URL / SCRIPT_URI, as
there are some [old] PHP scripts that rely on these variables set
normally by Apache.