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/

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_param SCRIPT_FILENAME $request_filename;
include fastcgi_params;

Reference :