WordPress is one of the most popular open source content management systems today, and it’s written in PHP, and both PHP and WordPress can run on NGINX.
Nginx make sites faster, but it definitely has an upper edge in serving static content. That’s why, many WordPress users switch to Nginx.
Often, this switch cause Nginx WordPress permalinks 404 errors. This happens as Apache’s rewrite rules do not work with NGINX.
Details of WordPress permalinks 404 error
Only the home page is working, where as every other page returns a 404 not found error.
What causes permalinks 404 error in Nginx?
Nginx and Apache rewrite rules have totally different format. The directives in Apache like Rewritecond, RewriteRule, etc. take its equivalents in Nginx configuration.
mod_security rules will not work with NGINX, and .htaccess rewrite rules and restrictions will no longer apply.
This means that WordPress permalink rewrites will no longer work after switching the web server.
Fixing WordPress permalinks 404 error on Nginx server
-
Converting rewrite rules to Nginx format
A quicker method to fix the permalink error is to convert the Apache rewrite rules to Nginx format. Either we can manually rewrite the rules or use various plugins for automatic conversion.
-
Modifying Nginx configuration
Similarly, modifying the Nginx configuration also helps in solving the WordPress permalinks 404 error.
Edit the following location block within the server block:
location / {
try_files $uri $uri/ /index.php?$args;
}