nginx config for single wordpress blog

When you are using LEMP stack for your server, you probably struggle with ngnix configuration with some errors such as : cannot load js, css file, can not access wp admin, cannot open input file.

Below are some blocks need to have in your configuration file. All blocks below are in server block (in my case, i put all in my virtual host configuration file eg: /var/etc/nginx/site-availables/example.com.conf)

Url rewriting for permanent link:

if (!-e $request_filename) {
rewrite /wp-admin$ $scheme://$host$uri/ permanent;
rewrite ^(/[^/]+)?(/wp-.*) $2 last;
rewrite ^(/[^/]+)?(/.*\.php) $2 last;
}

Location block:

location / {
try_files $uri $uri/ /index.php?q=$uri&$args;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $request_filename;
include fastcgi_params;
}

Reference :

  1. https://rtcamp.com/wordpress-nginx/tutorials/multisite/subdirectories/w3-total-cache/
  2. http://blog.martinfjordvald.com/2011/01/no-input-file-specified-with-php-and-nginx/