Getting a 404 After Moving WordPress to Nginx

Last updated on | one reply

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 if this helped. Follow me on Twitter, Facebook and YouTube, or 🍊 buy me a smoothie.

1 reply

Leave a reply

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