π« What Causes the Nginx WordPress Permalinks 404 Error?
When switching from Apache to Nginx, the main issue is that:
πΉ Apache uses .htaccess for URL rewriting
πΉ Nginx does NOT support .htaccess files
πΉ WordPress permalinks rely on rewrite rules
Since Nginx handles URL rewriting differently, WordPress permalinks break unless the correct Nginx configuration is added manually.
Also, note:
mod_security rules and Apache rewrite formats do not apply to Nginx.
You must use native Nginx rules instead.
βοΈ How to Fix Nginx WordPress Permalinks 404 Error
You need to manually edit the Nginx configuration files for your domain.
π File locations on VestaCP:
/home/admin/conf/web/domain-name.nginx.conf
/home/admin/conf/web/domain-name.nginx.ssl.conf
Both files must be updated to support HTTP and HTTPS.
π Step 1: Open the Nginx Configuration File
cd /home/admin/conf/web/
vim domain-name.nginx.conf
# or for SSL:
vim domain-name.nginx.ssl.conf
Press i in vim to enter insert mode.
π οΈ Step 2: Add the Correct Location Block
β Recommended (Try Files Method β Most Reliable)
location / {
try_files $uri $uri/ /index.php?$args;
index index.html index.htm index.php;
}
This rule checks if the request is a file or directory, and if not, it passes it to index.php, which handles WordPress permalinks.
π‘ Alternative Solution (Rewrite Method)
If the first solution doesnβt work, try this method:
location / {
rewrite ^/(.*)$ /index.php?$1;
index index.html index.htm index.php;
}
This rule forcefully rewrites all URLs to index.php, allowing WordPress to process them.
πΎ Step 3: Save and Exit in Vim
Press:
ESC
:wq
π Step 4: Reload Nginx to Apply Changes
nginx -s reload
β¨ Your WordPress Permalinks Should Now Work Perfectly!
Once done, visit your WordPress dashboard and go to:
Settings β Permalinks β Save Changes (no need to change anything β just resave).
This refreshes your permalink structure.
π Bonus: Basic Vim Commands (For Beginners)
| Command | Action |
|---|---|
i | Enter insert mode |
ESC | Exit insert mode |
:w | Save changes |
:q | Quit |
:wq | Save and quit |
:q! | Quit without saving |
π Post Tags:
#404 #Linode #PHP #PHP-FPM #Ubuntu18.04 #VestaCP #Nginx #Permalinks #WordPress