Troubleshooting 404 Not Found in NGINX
A 404 Not Found error means NGINX could not find the requested page or file. Sometimes the website is genuinely missing the page, but on hosting servers it often comes from an incorrect root path, wrong server block, missing rewrite rules, or application routing not being passed correctly.
Step 1: Confirm the domain points to the right server:
dig example.com +short
Make sure the IP matches your VPS.
Step 2: Check which server block is handling the domain:
sudo nginx -T | grep -A20 -B5 “server_name example.com”
This helps confirm NGINX has loaded the correct configuration.
Step 3: Check the document root:
ls -la /var/www/example.com/public
Make sure the requested file exists.
Step 4: For Laravel, WordPress, and other apps with pretty URLs, confirm your location block includes a fallback such as try_files. Without it, NGINX may look for physical files only and return 404 on application routes.
Step 5: Test the config:
sudo nginx -t
Step 6: Reload:
sudo systemctl reload nginx
Useful log commands:
sudo tail -f /var/log/nginx/access.log sudo tail -f /var/log/nginx/error.log
The access log shows which URL was requested and what status code was returned. The error log may show file path problems.
A simple test is to add a plain test file, such as test.html, into the web root and visit it directly. If test.html loads but application pages do not, the issue is probably routing or rewrite configuration. If test.html does not load, the issue is likely DNS, server block matching, root path, or permissions.