WordPress – Solving 404 error when changing permalinks on Nginx

I’m currently running WordPress on a Virtual Linux Machine (Debian 11) using Nginx as my web server engine.
Being new to the world of blogging I noticed my URL’s end with https://richay.com.au/?page_id=2
Where an easier URL to remember would be much better. This feature is offered in the admin panel of WordPress in Settings -> Permalinks
Where I chose to have my post name as my link.

This immediately gave 404 errors on all except my homepage of https://richay.com.au/
To remedy this and have my links working again, I had to edit my Nginx default settings:

sudo nano /etc/nginx/sites-enabled/default


Replacing the part of the code:

location / {
    try_files $uri $uri/ =404;
}


With:

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


All links started working instantly and my page does not show the miserable 404 error.
My blog page is now https://richay.com.au/blog/

🙂

Leave a Reply

Your email address will not be published. Required fields are marked *