Nginx + php-fpm "modern configuration way"

Hello,

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?

fastcgi_split_path_info ^(.+.php)(/.+)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;

Regards,
Gregory

2012/4/3 Grégory Pakosz [email protected]:

However, I often see the following directives being used, how
important/useful are they?

fastcgi_split_path_info ^(.+.php)(/.+)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;

Those are to handle urls like
www.example.com/index.php/some/para/meters.

fastcgi_split_path_info ^(.+.php)(/.+)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;

Those are to handle urls like www.example.com/index.php/some/para/meters.

Well then Wordpress, Drupal and Joomla can do without them. From your
remark, I deduce some other PHP scripts can’t

Regards,
Gregory

Edho A. Wrote:

Those are to handle urls like
www.example.com/index.php/some/para/meters.

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…

Andrejs

Posted at Nginx Forum:

A lot of forums use it for their “archive mode”. Look at vBulletin /
MyBB
for examples.

2012/4/3 Grgory P. [email protected]

Thank you all for your reply

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.

Gregory

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.

–appa

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.

nginx.conf:

http {

map $uri $script_url {
~^(?<script_filename>.+.(php|html))(?<path_info>.+)$
$path_info;
~^(?<script_filename>.+.(php|html))$ $script_filename;
}

}

fastcgi_php.conf:

include fastcgi_params;

      fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
      fastcgi_param SCRIPT_FILENAME

$document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED
$document_root$fastcgi_path_info;

      fastcgi_param  SCRIPT_URL $script_url;
      fastcgi_param  SCRIPT_URI $scheme://$http_host$script_url;

      try_files $fastcgi_script_name = 404;

Posted at Nginx Forum: