PHP-FPM in Nginx

Due to Nginx's support for fastcgi servers, configuring a site for PHP with php-fpm is a very easy matter. Assuming your php-fpm instance is running on port 9000, simply add the following code your site's server{} virtualhost container.

location ~ \.php$ {
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index index.php;
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}

Any request made to a *.php file will then be handled through the the php-fpm fastcgi process on port 9000. Be sure to also add 'index.php' to your index listing.

Clean URLs

If you're using a CMS, such as Wordpress or Joomla, and wish to use 'clean' URLs, a rewrite rule will need to be created to redirect all requests for non-existent files through PHP. This can be done with the following configuration to your server container.

location / {
    if (!-e $request_filename)
    {
        rewrite ^/(.*)$ /index.php?/$1 last;
        break;
    }
}