Nginx WordPress permalinks 404 error Page not found

Nginx make sites faster. But, Nginx causes WordPress permalinks 404 errors. This happens as Apache’s rewrite rules do not work with NGINX.  On this post we will learn to WordPress permalinks in Nginx.

WordPress pretty permalinks optimized to be SEO friendly and are compatible with the most popular web servers:

  • Apache: using mod_rewrite module.
  • Nginx: using try-files.
  • Lighttpd: using mod_rewrite or a 404 handler.
  • Microsoft IIS 7+ using URL Rewrite 1.1+ module and PHP 5 running as FastCGI
  • Microsoft IIS 6+ working with ASAPI_Rewrite or Ionic ISAPI Rewriting Filter (IIRF)

Why Nginx WordPress permalinks 404 error Page not found?

Technically, anyone who choose PHP-FPM as the PHP handler, as WordPress recommends. And, to take advantage of NGINX, i recommend to enable PHP-FPM on all domains that serve PHP.

Unfortunately, mod_security rules will not work with Nginx, and .htaccess rewrite rules and restrictions will no longer apply. Nginx and Apache rewrite rules have totally different format. The directives in Apache like Rewritecond, RewriteRule and more take its tolls in Nginx configuration. This means that WordPress permalink rewrites will no longer work after switching to Nginx.

Fixing Nginx WordPress permalinks 404 error Page not found

We can set our really cool permalink configuration directly by editing Nginx. We will use try_files directive so WordPress can start using pretty permalinks. Let’s see the configuration for WordPress installed on the root of your domain.

Search for the location / block inside nginx configuration and add the following line inside:

location / {
	 # WordPress permalinks in Nginx
	 try_files $uri $uri/ /index.php?$args;

On this code, we are letting Nginx checking the existance of a file at the URL usign $uri, then it searches for directory ($uri/), and if it doesn’t find any of both, it will make an internal redirect to /index.php with the arguments from the query string as parameters.

After editing, save your file, and reload Nginx to apply changes:

service nginx reload


systemctl reload nginx.service

Alternatively, in servers with Plesk control panel, we just had to add the rules in the “Additional Nginx directives” section inside the domain settings at Domains > > Apache & nginx Settings. That fixed the permalinks and the website started working again.

if (!-e $request_filename) {
set $test P;
if ($uri !~ ^/(plesk-stat|webstat|webstat-ssl|ftpstat|anon_ftpstat|awstats-icon|internal-nginx-static-location)) {
set $test "${test}C";
if ($test = PC) {
rewrite ^/(.*)$ /index.php?$1;

On the other hand, in servers with CPanel. Please bear in mind that Nginx configuration file refers to the user’s config file at this location where $USERNAME represents the username:


Next, you need to add this snipprt to the config file above: (/wordpress here refers where the WordPress installation is configured to be available)

location /wordpress { try_files $uri $uri/ /wordpress/index.php?$args; location ~ \.php7?$ { include conf.d/includes-optional/cpanel-fastcgi.conf; fastcgi_pass unix:/opt/cpanel/ea-php73/root/usr/var/run/php-fpm/1ed179754201ac2644e8c70140bacb23c7786484.sock; error_page 502 503 /FPM_50x.html; } }

Finally, you restart Nginx gracefully by running this command:



Nginx wordpress permalinks 404 error page not found occurs when the rewrite rules do not follow the Nginx format. The fix involves converting the rules and modifying Nginx configuration.

You may also like...