Networking HowTos
Networking HowTos

Enable Permalinks in WordPress on Nginx

July 16, 2012 Linux

A default installation of WordPress on Nginx is not going to allow the use of Permalinks.
Since Nginx doesn’t support the Apache .htaccess files, the Nginx configuration files need to be edited manually to suit.
To enable permalinks in Nginx:
Edit the configuration file associated with your WordPress site.
Eg:

$ sudo nano /etc/nginx/sites-enabled/sitename.conf

Locate the “location /” code block, located within the “server” block, and add the following line within:

try_files $uri $uri/ /index.php?q=$uri&$args;

Example config file:

server {
        listen 80 default;
        server_name www.sitename.com sitename.com;
        root /var/www/sitename;
        index index.php index.html index.htm;
        error_page 404 /404.html;
        port_in_redirect off;
        location / {
            try_files $uri $uri/ /index.php?q=$uri&$args;
        }
        location ~ \.php$ {
            try_files $uri =403;
            fastcgi_pass unix:/var/run/php5-fpm-websites.sock;
            include fastcgi_params;
        }
        location ~ /\.ht {
            deny all;
        }
}

You should now be able to make use of permalinks in WordPress running on a Nginx server.

You Might Also Like