# Nginx + php-fpm "modern configuration way"

**URL:** <https://www.ruby-forum.com/t/nginx-php-fpm-modern-configuration-way/218521>\
**Category:** NGINX\
**Created:** [April 3, 2012, 10:50am UTC](https://www.ruby-forum.com/t/nginx-php-fpm-modern-configuration-way/218521 "2012-04-03T10:50:46Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [April 3, 2012, 10:50am UTC](https://www.ruby-forum.com/t/nginx-php-fpm-modern-configuration-way/218521/1 "2012-04-03T10:50:46Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [April 3, 2012, 10:52am UTC](https://www.ruby-forum.com/t/nginx-php-fpm-modern-configuration-way/218521/2 "2012-04-03T10:52:38Z")

</div>

2012/4/3 Grégory Pakosz [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> 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](http://www.example.com/index.php/some/para/meters).

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [April 3, 2012, 11:03am UTC](https://www.ruby-forum.com/t/nginx-php-fpm-modern-configuration-way/218521/3 "2012-04-03T11:03:11Z")

</div>

> > 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](http://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

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [April 3, 2012, 11:06am UTC](https://www.ruby-forum.com/t/nginx-php-fpm-modern-configuration-way/218521/4 "2012-04-03T11:06:18Z")

</div>

## Edho A. Wrote:

> Those are to handle urls like  
> [www.example.com/index.php/some/para/meters](http://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:  
[http://forum.nginx.org/read.php?2,224829,224834#msg-224834](http://forum.nginx.org/read.php?2,224829,224834#msg-224834)

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [April 3, 2012, 12:20pm UTC](https://www.ruby-forum.com/t/nginx-php-fpm-modern-configuration-way/218521/5 "2012-04-03T12:20:49Z")

</div>

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

2012/4/3 Grgory P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [April 3, 2012, 8:56pm UTC](https://www.ruby-forum.com/t/nginx-php-fpm-modern-configuration-way/218521/6 "2012-04-03T20:56:58Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [April 3, 2012, 11:08am UTC](https://www.ruby-forum.com/t/nginx-php-fpm-modern-configuration-way/218521/7 "2012-04-03T11:08:11Z")

</div>

> 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

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [April 3, 2012, 11:13pm UTC](https://www.ruby-forum.com/t/nginx-php-fpm-modern-configuration-way/218521/8 "2012-04-03T23:13:16Z")

</div>

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:

> **[Re: nginx + php-fpm "modern configuration way"](https://forum.nginx.org/read.php?2,224829,224900#msg-224900)**
>
> 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\_pa
