How to fix: 404 not found Nginx Error.

NGINX logo

You know how frustrating it can be if you’ve encountered the dreaded “404 not found” error while using Nginx. This error means that the server cannot find the requested resource, and it’s a common issue with various causes. This blog post will review some of the most common causes of the “404 not found” error and how to fix them. Whether you’re a seasoned developer or new to web development, this post will provide the tools you need to troubleshoot and fix this not found error.

Troubleshooting: 404 not found Nginx

Follow these simple steps to get your web server running again using this tutorial:

  1. Check Nginx Configuration File

    nginx config

    This error is typically caused by a configuration error in the nginx.conf file.

    To find your nginx.conf configuration file, you can enter nginx -t in your command line.

    The file is typically located under /etc/nginx/ if you are having an issue finding the filename.

    If you are unsure what the nginx config file should look like, here is an example to see the correct rewrite rules and sites-enabled settings.

    The most common setup is configuring Nginx as a reverse proxy for Apache.

    The last step is to check the index.html (static) or index.php (WordPress) files, if they are in the correct location of the document root.

  2. Check the Error Logs

    nginx error-log

    The next step is to check the access and error logs for clues:

    /var/log/nginx/error.log
    /var/log/nginx/access.log.

    Errors in the logs will help you to understand what is wrong with the configuration causing an error page.

    If the application is PHP-based then it is good to check if the PHP-FPM service is up and running.

  3. Start, Stop, Restart Nginx

    start nginx service

    Some times the server has stopped, creating an error. Just to be safe, it would be best to stop/start, or restart Nginx to see if any errors occur.

    To Start Nginx, enter one of the following commands for Ubuntu or any Linux server:

    sudo service nginx start
    sudo systemctl start nginx

    To Stop Nginx, enter one of the following command:

    sudo service nginx stop
    sudo systemctl stop nginx

    Finally, to Restart Nginx, enter one of the following command:

    sudo service nginx restart
    sudo systemctl restart nginx
  4. Rebuild your Server

    NGINX logo

    Don’t get stuck in a Sunk Cost Fallacy approach.  Sunk Cost Fallacy is a logical fallacy that entails sticking with a losing or failed venture because you’ve already invested a significant amount of time, money, or other resources that you can’t get back.

    So if you have a new virtual private server without any live production sites, it might be better to start a fresh cloud instance (on DigitalOcean, AWS, Vultr, etc,.) and meticulously track your startup procedures to see if you are accidentally creating an error, then try to fix a jumbled mess of code.

Conclusion

The “404 not found” error on Nginx is a common and frustrating issue with multiple causes. However, this blog post aims to provide a resource for individuals of all skill levels to troubleshoot and fix this error. By following the steps outlined in this post, you’ll be able to resolve the “404 not found” error and get your Nginx server up and running smoothly again.

About Isaac

I am a digital marketing consultant located in Ottawa, Ontario. My focus is on Technical SEO, Web Design, and Content optimization for small to medium-sized businesses.

Published on: 2023-01-08
Updated on: 2023-01-11

Top