Todi ! — Bismillah :)

WordPress Permalink Configuration for NGINX

When running WordPress behind NGINX, pretty permalinks won't work out of the box. Unlike Apache, NGINX doesn't use .htaccess files — you need to add rewrite rules directly into your server block configuration.

NGINX Server Block Configuration

Add the following location block inside your server directive to handle WordPress rewrite rules for clean URLs:

location / {
    try_files $uri $uri/ /index.php?$args;
}

This single line tells NGINX to first try the requested URI as a file, then as a directory, and finally fall back to index.php with the original query arguments — exactly what WordPress needs for its permalink structure.

Full Example

A minimal NGINX server block for a WordPress site might look like this:

server {
    listen 80;
    server_name example.com;
    root /var/www/wordpress;

    index index.php index.html;

    location / {
        try_files $uri $uri/ /index.php?$args;
    }

    location ~ \.php$ {
        include fastcgi_params;
        fastcgi_pass unix:/run/php/php-fpm.sock;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }
}

After Configuration

Once the server block is updated, reload NGINX with nginx -s reload (or systemctl reload nginx). Then go to your WordPress admin area, navigate to Settings → Permalinks, choose your preferred structure (such as "Post name"), and save. The clean URLs should now work immediately.

See more tutorials in the Tutorials section.