Getting a 404 After Moving WordPress to Nginx

Last updated on

You will need to edit the config file to instruct Nginx to direct requests to index.php.

Open your config file. The default location is /etc/nginx/sites-enabled/default, however, if you followed an earlier guide setting up multiple domains in Nginx, your config may be located in /etc/nginx/sites-enabled/example.com.

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

Scroll down to the location / block. It should look something like this:

/etc/nginx/sites-enabled/default
        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                try_files $uri $uri/ =404;
        }

Change it to:

/etc/nginx/sites-enabled/default
        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                try_files $uri $uri/ /index.php?$args;
        }

This will direct PHP requests to the WordPress index.php file.

Save file and exit. (Press CTRL + X, press Y and then press ENTER)

Now reload Nginx config

sudo service nginx reload

Let me know in the comments if this helped. Follow me on Twitter, Facebook and YouTube.

p.s. I increased my AdSense revenue by 68% using AI 🤖. Read my Ezoic review to find out how.

1 Star2 Stars3 Stars4 Stars5 Stars 5.00 (1 votes)

Leave a Reply

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

We use Markdown to style comments, like on Github and Reddit.
To do a line break, type two spaces after the sentence.
You can add inline code by wrapping it in backticks: `code here`

    To do an entire block of code  
    type four spaces before the line
    and it will appear in a block like this.
    <-- four empty spaces

1 reply