Wordpress Config For Nginx PHP-FPM

Here’s how you can setup nginx and php-fpm for use with wordpress. It is assumed you have nginx and and php-fpm installed.


  • Domain mycooldomain1.com pointing to <server ip>
  • wordpress installed on /usr/share/mycooldomain1.com_wordpress
  • php-fpm listening on port 9000

Then on /etc/nginx/nginx.conf:

http {
  server {

    server_name mycooldomain1.com;
    access_log /var/log/nginx/mycooldomain1.com.access.log main;
    error_log /var/log/nginx/mycooldomain1.com.error.log;

    location / {
      root /usr/share/mycooldomain1.com_wordpress;
      index index.php index.html index.htm;
      # unless request is for a valid file, send it as a query to index.php
      # this will allow clean url (eg: mycooldomain1.com/hello/world)
      if(!-e $request_filename)
        rewrite ^(.+)$ /index.php?q=$1 last;

    location ~ \.php$ {
      fastcgi_pass   localhost:9000;
      fastcgi_index  index.php;
      fastcgi_param  SCRIPT_FILENAME  /usr/share/mycooldomain1.com_wordpress;
      fastcgi_param  REQUEST_METHOD   $request_method;
      fastcgi_param  CONTENT_TYPE     $content_type;
      fastcgi_param  CONTENT_LENGTH   $content_length;
      include        fastcgi_params;

Restart both nginx and php-fpm once you’ve updated the config:

sudo service nginx restart
sudo service php-fpm restart

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s