RackUp IT - View Cloud Hosting Plans

Get started now or speak directly with our engineering team for specialized assistance.

Logo
DevelopmentWEB & APPCalculatorTOOLServicesProductBlogOur TeamCareers
View Plans
Home>Blog>404 Not Found in Nginx: Why It Happens and How to Fix It
VPS Hosting

404 Not Found in Nginx: Why It Happens and How to Fix It

Alex Vance
Alex Vance
Published Oct 10, 2026· Updated Nov 13, 2026•✓ Verified Expert Reviewed•3 min read
404 Not Found in Nginx guide cover

Key Takeaways

  • ✓The error log shows the exact file path Nginx tried; compare it to where the file really is.
  • ✓root and alias behave differently, and mixing them up is the most common cause.
  • ✓WordPress permalinks and React/Vue apps need try_files or every inner page 404s.
  • ✓Check that the right server block and site are actually enabled.

Table of Contents

  • •404 Not Found in Nginx: Why It Happens and How to Fix It
  • •Step 1: See the Path Nginx Looked For
  • •Cause 1: root vs alias Confusion
  • •Cause 2: Missing try_files (WordPress, Laravel, React, Vue)
  • •Cause 3: The Wrong Server Block Answers
  • •Cause 4: The Site Is Not Enabled
  • •Cause 5: Case and File Name Mismatch
  • •Cause 6: A More Specific location Block Wins
  • •Cause 7: The App Returns the 404
  • •Bonus: Show a Custom 404 Page
  • •Frequently Asked Questions
  • •Rather Not Debug Nginx at 2 AM?

404 Not Found in Nginx: Why It Happens and How to Fix It

A 404 Not Found page with nginx (or nginx/1.20.1 and similar) underneath means Nginx itself could not map the URL to a file or a route. When the page clearly exists on disk or in your app, the cause is nearly always configuration. The fastest way to find it is to see which path Nginx actually tried.

Not running Nginx, or only visiting a site that shows this error? Read 404 Not Found: what it means and how to fix it.

Step 1: See the Path Nginx Looked For

sudo tail -n 30 /var/log/nginx/error.log

You will see a line like:

open() "/var/www/html/images/logo.png" failed (2: No such file or directory)

Compare that path to where the file really is. The difference points straight at the cause below. If no line appears, the 404 is coming from your application (Cause 7).

Cause 1: root vs alias Confusion

root appends the full request path; alias replaces the location part. With this config:

location /static/ {
    root /var/www/app/static/;
}

a request for /static/app.css looks for /var/www/app/static/static/app.css (note the doubled folder) and returns 404. Use alias instead:

location /static/ {
    alias /var/www/app/static/;
}

Keep the trailing slash on both the location and the alias.

Cause 2: Missing try_files (WordPress, Laravel, React, Vue)

Pretty URLs do not exist as files, so the app has to receive them. Without try_files, every page except the homepage returns 404.

# WordPress / Laravel / most PHP apps
location / {
    try_files $uri $uri/ /index.php?$args;
}

# React, Vue, Angular single-page apps
location / {
    try_files $uri /index.html;
}

If WordPress shows the homepage but every post 404s, this is your fix.

Cause 3: The Wrong Server Block Answers

If no server_name matches the requested domain, Nginx uses the default server, which serves a different root. List what is configured:

sudo nginx -T | grep -E "server_name|listen|root"

Check that your domain (including the www version) is in server_name, and that only one block is marked default_server per port.

Cause 4: The Site Is Not Enabled

On Ubuntu and Debian, configs in sites-available do nothing until they are linked into sites-enabled:

ls -l /etc/nginx/sites-enabled/
sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/
sudo rm /etc/nginx/sites-enabled/default   # if the default site is catching requests

Cause 5: Case and File Name Mismatch

Linux file names are case-sensitive. Logo.PNG and logo.png are different files, which often breaks sites moved from Windows or macOS. Check with ls and fix the file or the link.

Cause 6: A More Specific location Block Wins

Nginx picks exact matches (=) first, then the longest prefix marked ^~, then regex locations in order, then the longest plain prefix. A regex block such as location ~* \.(css|js|png)$ with its own root can catch requests you expected another block to handle. Give it the same root or narrow the regex.

Cause 7: The App Returns the 404

When Nginx proxies to Node.js, Python or a container, a 404 may come from the app, not Nginx. Test the upstream directly:

curl -I http://127.0.0.1:3000/the-path

If the app also returns 404, fix its routes or base path. A common case is an app expecting to live at / while Nginx serves it under /app/: the trailing slash in proxy_pass http://127.0.0.1:3000/; strips the prefix, and without it the prefix is passed through.

Bonus: Show a Custom 404 Page

error_page 404 /404.html;
location = /404.html {
    internal;
}

Then sudo nginx -t && sudo systemctl reload nginx. For other codes see common Nginx errors and fixes, and for permission problems see 403 Forbidden in Nginx.

Frequently Asked Questions

Why does Nginx say 404 Not Found when the file exists?
Nginx is looking in a different place than you expect. Check the path in the error log; it is usually a root vs alias mistake, a missing try_files rule, or the wrong server block answering.

Why do WordPress posts return 404 on Nginx?
Nginx does not read .htaccess. Add try_files $uri $uri/ /index.php?$args; to the location / block.

Why does my React app 404 on refresh?
The browser asks the server for a route that only exists in the JavaScript app. Use try_files $uri /index.html; so Nginx returns the app shell for unknown paths.

What is the difference between 404 and 403 in Nginx?
404 means Nginx could not find anything at the path. 403 means it found it but is not allowed to serve it.

Rather Not Debug Nginx at 2 AM?

Every error in this guide is something a managed host fixes for you. RackUp IT managed hosting runs a tuned Nginx, PHP and caching stack with monitoring, backups and SSL handled, so you can spend your time on the site instead of the server.

← Previous Article403 Forbidden in Nginx: 6 Causes and How to Fix Each OneNext Article →Common Nginx Errors and How to Fix Them (400 to 504)
Interactive 60-Second Tool

Unsure Which Cloud Hosting Plan Fits Your Site?

Answer 4 quick diagnostic questions to estimate the server CPU, RAM and storage you need with transparent pricing.

Free Migration 99.9% Uptime Target
Calculate My Hosting Build
Alex Vance
Written ByAlex Vance

Cloud Infrastructure Engineer.

99.9% Uptime Target

RackUp IT - View Cloud Hosting Plans

View Hosting Plans

View Hosting Plans

CONTENTS

  • 404 Not Found in Nginx: Why It Happens and How to Fix It
  • Step 1: See the Path Nginx Looked For
  • Cause 1: root vs alias Confusion
  • Cause 2: Missing try_files (WordPress, Laravel, React, Vue)
  • Cause 3: The Wrong Server Block Answers
  • Cause 4: The Site Is Not Enabled
  • Cause 5: Case and File Name Mismatch
  • Cause 6: A More Specific location Block Wins
  • Cause 7: The App Returns the 404
  • Bonus: Show a Custom 404 Page
  • Frequently Asked Questions
  • Rather Not Debug Nginx at 2 AM?

Categories

  • VPS Hosting
  • DevOps & Tutorials
  • WordPress Hosting
  • Cloud Hosting
  • Server Stack
  • Networking & Security
  • Web Hosting / Managed Cloud
  • E-Commerce
  • Hosting & SEO
  • Hosting Benchmarks
  • Cloud Backup & DevOps
  • Managed VPS

Recent Posts

  • Vultr Alternatives in 2026: VPS Hosting for Developers Compared
  • Docker Port Mapping Explained: -p, EXPOSE and Compose ports
  • Bluehost Alternatives (2026): WordPress Hosting Without the Renewal Price Jump

Tags

Nginx404 Not FoundTroubleshootingWordPressReactVPS Hosting

Related Posts

Vultr alternatives coverVPS Hosting
Nov 27, 2026

Vultr Alternatives in 2026: VPS Hosting for Developers Compared

Vultr's Regular Performance prices compared with DigitalOcean, Linode, Hetzner and a fixed-plan VPS at the 8 GB size, plus when container hosting fits better.

Read Article →
What is a VPS? Virtual private servers explainedVPS Hosting
Nov 20, 2026

What Is a VPS? Virtual Private Servers Explained

A VPS (virtual private server) is a virtual machine with its own operating system, resources and root access. How it works, uses, and when you need one.

Read Article →
Linode alternatives coverVPS Hosting
Nov 19, 2026

Linode (Akamai) Alternatives in 2026: VPS Hosting Compared

Linode's shared CPU prices from Akamai's own API, compared with DigitalOcean, Vultr and a fixed-plan VPS, plus when container hosting makes more sense.

Read Article →
Logo

Expert Web & App Development, UI/UX Design, Branding, and Consulting to scale your business.

Company

  • About Us
  • Blog
  • Contact
  • Our Team
  • Careers

Services

  • Web Development
  • App Development
  • UI/UX Design
  • Consulting
  • Managed WordPress VPS
  • Website Speed Test

Subscribe to our newsletter

We accept
  • bKash
  • Nagad
  • Rocket
  • Upay
  • CellFin
  • Meghna Pay
  • OK Wallet
  • Tap
  • mCash
  • DBBL Nexus
  • Visa
  • Mastercard
  • American Express
  • Crypto
Pay with Visa, Mastercard, American Express, DBBL Nexus, CellFin, Rocket, bKash, Tap, Meghna Pay, Nagad, mCash, Upay and OK Wallet. Verified by EPS

© 2026 Rackup IT Solution. All rights reserved.

Privacy PolicyTerms of Service