October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
VGSources
Blog

How to Fix a 404 Not Found Error on Nginx

A practical Nginx 404 troubleshooting guide: identify whether Nginx or your backend returned the error, map the URI correctly, repair try_files and proxy paths, and verify the fix safely.
Length12 min Posted Quest giverVGSources Team

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

An Nginx 404 means the requested URL did not resolve to a file, directory, or application route. Find out first whether Nginx generated the response while mapping the URI to disk or whether an upstream application returned it. Then inspect the active server and most specific location block, verify the root/alias path, check try_files, and compare Nginx and application logs before changing files.

The same status code has different fixes: a wrong filesystem path requires an Nginx configuration change, while a backend-generated 404 requires correcting the application route or the URI sent through proxy_pass. Use the workflow below to identify that distinction without guessing.

As an Amazon Associate I earn from qualifying purchases.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

1. Determine which layer returned the 404

Start with the response itself. Look at the headers and body, then compare the Nginx access and error logs with the log of the application behind Nginx. A response generated by Nginx often has a standard Nginx error page or an error-log entry showing a failed local lookup. A response generated by an upstream service may contain that application’s JSON, HTML, or distinctive headers.

This distinction controls every later step:

  • Nginx-generated 404: the selected configuration mapped the URI to a path that does not exist, or a try_files rule deliberately returned 404.
  • Upstream-generated 404: Nginx reached the backend, but the backend has no route for the URI it received.

Do not add random files to the web root until you know which case you have. A backend route cannot be repaired by creating a static placeholder, and a missing static asset cannot be fixed by changing application routing.

#1 Best Overall
Sale
Gaoye Blue Light Blocking Glasses
  • BLUE LIGHT BLOCKING GLASSES: Our blue light glasses for women boast UV400 protection, blocking harmful blue rays from computer screens. With these bluelight glasses women, you can enjoy gaming, reading, or watching TV with no worries of eye strain.
  • EYE RELIEF: Our blue light glasses are engineered to reduce blurry vision or strain caused by prolonged screen time. These womens blue light glasses aid in better sleep by preventing blue light from disrupting your natural sleep cycle, helping you fall asleep faster and enjoy a more restful night's sleep, making them the perfect christmas present.
  • COMFORTABLE: Crafted from durable material, our trendy blue light glasses for woman or blue light glasses men ensure long-lasting comfort. The high-transmittance lenses accessories, gamer gifts for men, help keep your eyes relaxed. Perfect stocking stuffers, gifts for gamers men, christmas gifts for men, halloween costumes.
  • LIGHTWEIGHT: These clear blue light glasses feature a lightweight frame, meaning they’ll stay comfy for long-term wear. Perfect as blue blockers glasses for women or mens blue light glasses, these non-prescription fake glasses for men can be worn throughout the day. The blue light blocking glasses women feature polycarbonate HD lenses, which are anti-reflective and restore true color.
  • WORRY-FREE PURCHASE: If you experience any issues, our support team is ready to assist you quickly. These are the perfect costume glasses for cosplay dressing up.

2. Inspect the effective server and location

Nginx chooses a server block using the request’s hostname and port, then chooses the most specific matching location. A correct directive in an unused virtual host or a less-specific location will not affect the failing request.

Confirm the request identity

  • Use the exact hostname in the request, including whether it is the bare domain or a subdomain.
  • Check the port and protocol. HTTP and HTTPS may select different server blocks.
  • Check the URI byte-for-byte, including capitalization, extension, URL-encoded characters, and a trailing slash.

Confirm the matching location

Review the active configuration and identify the location that handles the failing path. A nested or prefix location can override the location / block you expected. Pay particular attention to locations for assets, API paths, and single-page applications, because each may use a different root, alias, or proxy rule.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

After identifying the block, verify that its document directory is the directory where the deployment actually placed the file. A release copied to a new directory while the configuration still points to an old release is a common cause of an apparently inexplicable 404.

3. Understand how root and alias build paths

The difference between these directives is the source of many Nginx 404s. With root, Nginx appends the complete request URI to the root directory. With alias, Nginx replaces the location prefix with the alias target.

Directive Request Filesystem path Nginx checks Use when
root /srv/www/site; /images/logo.png /srv/www/site/images/logo.png The URI path should be appended to one document directory.
location /images/ { alias /srv/assets/; } /images/logo.png /srv/assets/logo.png The location prefix should be replaced by a different directory.

For a root directive, verify the directory plus the entire URI. For an alias directive, verify that the location prefix and alias trailing slash produce the intended replacement. For example, location /assets/ { alias /srv/assets/; } maps /assets/app.css to /srv/assets/app.css; a mismatched slash or an alias that includes an unintended extra directory can point Nginx somewhere else.

Check the file and its parent directories

  • Confirm the requested filename exists at the resolved path.
  • Check case exactly. Linux filesystems normally treat App.js and app.js as different names.
  • Confirm the extension and URL encoding match the deployed file.
  • Ensure the Nginx worker can traverse every parent directory and read the file. A permissions or access-control problem may appear in the error log even when the file exists.

If the resolved path is wrong, correct the applicable root or alias, deploy the file to the path Nginx is already using, or change the request URL. Do not switch directives merely because one spelling looks shorter.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

4. Check try_files in order

try_files tests files or directories in sequence. It uses the first match, internally redirects to that result, or executes the final fallback when no candidate exists. The final argument can be a URI, a named location, an upstream route, or an explicit status such as =404.

location / {
    try_files $uri $uri/ /index.html =404;
}

In this example, Nginx checks the URI as a file, then as a directory, then internally redirects to /index.html. If none of those choices resolves, it returns 404. The order matters: a broad fallback placed too early can hide a missing asset, while an explicit =404 placed before an application fallback prevents the request from reaching the application.

Rank #2
Windex Gaming Cleaning Wipes, Pre-Moistened Wipes to Instantly Clean all Gaming Gear and Electronics, Resealable Packaging for a Freshness Lock, 25 count (Pack of 1)
  • WINDEX GAMING WIPES: effortlessly clean all your gaming gear and gaming electronics in one easy step with our new Windex Gaming Wipes
  • AMMONIA FREE: our ammonia-free formula is safe to use on all of your favorite gaming equipment like consoles, headsets, controllers, screens, keyboards, and more
  • PRE-MOISTENED WIPES: each wipe instantly removes dust, dirt, and stubborn smudges and fingerprints leaving a streak-free shine
  • ANTI-STATIC: great for cleaning and wiping down your gaming gear and electronics leaving behind no visible residue
  • COMPACT RESEALABLE PACKAGE: store your pack of Windex Gaming Wipes anywhere in your home for whenever a quick and easy wipedown is needed

Static sites

For a conventional static site, point root at the directory containing the deployed files and make sure the fallback file exists there. If the site uses directory indexes, confirm the directory and index file are both present rather than assuming a trailing slash will create a page.

Client-side applications

A browser-side router may display routes that do not exist as physical files. In that case, a fallback such as /index.html is normally required for application routes, while missing static assets should still return 404. Keep the fallback narrow enough that a misspelled JavaScript or CSS filename is not silently replaced by the application shell.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Backend applications

For an application server, the last try_files argument can be a named location that proxies to the backend:

location / {
    try_files $uri $uri/ @application;
}

location @application {
    proxy_pass http://backend;
}

This pattern lets Nginx serve real local files and send other requests to the application. The backend still must define a route for the URI it receives.

5. Diagnose 404s from a reverse proxy

When Nginx proxies a request, verify two separate things: that the upstream service is reachable and that the upstream receives the URI your application expects. A reachable service can correctly return 404 for an incorrect path.

Verify the upstream request path

Inspect the proxy_pass form and the location that contains it. Whether the directive includes a URI component affects how Nginx constructs the path sent upstream. Compare that resulting path with the route registered by the application, including prefixes such as /api, version segments, and trailing slashes.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

For example, if the application serves /users but the proxy forwards /api/users, either mount the application route under /api or construct the proxy URI so the upstream receives /users. The correct choice depends on the application’s routing contract; adding a static file will not change it.

Verify connectivity separately

  • Confirm the upstream host and port resolve from the Nginx machine.
  • Check that the service is listening and healthy.
  • Use the application log to see the exact path, method, and host it received.
  • Check whether authentication, method restrictions, or a framework-level catch-all is producing the 404.

If the application log records the request and returns 404, fix its route or the proxy URI. If Nginx never reaches the upstream, investigate the proxy configuration and connectivity instead.

Rank #3
Sale
LISEN Cell Phone Stand Phone Holder for Desk, Office Decor Gadgets for Men
  • Ergonomic & Adjustable Design: Fight "text neck" and improve your posture. Designed for comfort, it offers an adjustable height (7.1in-8.5in) (1.4in adjustable range) and angle (5°-85°) Please note: cell phone stand is only 9 inches tall—the length of a standard pencil
  • Without blocking subtitles Perfect for office desk Tiktok Face Time Zoom video—this is the ultimate kitchen desk essential for phones! Perfect viewing experience while reducing neck back strain, A must-have for gamers streamers desk, and anyone who values both style and support!
  • Sleek & Stable Design fits Otterbox Case: Say goodbye to bent cables, tangles, and tip-overs! LISEN’s stylish adjustable desk phone holder features a built-in charging hole and smart cable management, keeping your phone secure and your workspace clutter-free cool gadgets for men
  • ANTI-SLIP DESIGN free hands: The under 10.00 items easy gadgets back and the bottom of this kitchen essentials for women are fully covered by anti-skid silicone, which LISEN stand up desk decor can provide maximum protection device from any scratches and slides
  • Your Perfect Viewing Companion:If your product arrives damaged or breaks within 365 days, reach out to LISEN for a quick and hassle-free solution. Struggling with assembly, like tightening the screw? We’ve got your back! Your experience matters to us. (Product including: phone Holder stand*1, screw*1, hexagon screwdriver*1, specification*1)

6. Read access and error logs before changing configuration

Logs usually reveal the URI Nginx handled, the selected behavior, and whether an upstream participated. Common installations place logs under /var/log/nginx; source installations may use /usr/local/nginx/logs. The exact location can differ, so inspect the configured path rather than assuming one directory.

To extract the compiled default error-log path, run:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
nginx -V 2>&1 | sed -n 's/.*--error-log-path=([^ ]*).*/1/p'

What to look for

  • An error such as “open() … failed (2: No such file or directory)” points to a local path or filename mismatch.
  • An entry showing an upstream status identifies a backend response; compare that status with the application log.
  • A request that never appears in the expected log suggests the request selected another server block, another Nginx instance, or a different proxy layer.
  • Repeated redirects or internal locations can expose a loop or an unintended fallback.

Correlate timestamps and request paths across Nginx and application logs. This is more reliable than inferring the cause from the appearance of an error page alone.

7. Validate, reload, and retest safely

Make one focused change at a time. Before reloading, run your installation’s normal configuration validation command (commonly nginx -t) and correct every reported error. A successful syntax check confirms that Nginx can parse the file; it does not prove that the path or route is correct.

  1. Save a copy of the working configuration or use your normal version-control workflow.
  2. Run the configuration test and review warnings as well as fatal errors.
  3. Reload Nginx with nginx -s reload or your service manager’s reload action.
  4. Request the exact failing URL again and record the status, headers, body, and timestamp.
  5. Test the canonical URL and deliberate variants: with and without a trailing slash, different filename case, the expected extension, and a query string.
  6. Recheck the access and error logs to confirm that the request used the intended server and location.

A reload applies configuration without requiring a full stop/start, but always verify the result from the same hostname and protocol that exposed the original problem.

8. Add a custom 404 only after routing works

Once normal file and application routing is correct, you can provide a custom response:

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
error_page 404 /404.html;

Nginx internally redirects the error to /404.html, so that file must exist and be served by a location that does not generate another 404. You can instead redirect the error or pass it to a backend, depending on the desired response behavior.

Keep the custom page separate from diagnosis. If it replaces the standard error body too early, it can hide whether the original failure came from local lookup or an upstream route. Temporarily request the custom target directly to ensure it resolves, and watch for recursive error handling in the logs.

Rank #4
Ledagic IC+RGBW USB Powered Led Light Bar with App & Remote Control, 2 Pack
  • Easy Installation: Our gaming lights have been designed to enhance your entertainment experience. Simply position the led light bar next to your TV or game console to create a game room environment with ease. They come with USB power and a 60 inch cord for direct mounting and mobility
  • Audio Syncing & Extensive Mode: The built-in high-sensitivity music sensor allows you to sync the TV led lights to your favorite music. Lights react and move to the beat of music, film and game audio, creating an incredible immersive sound and light experience – and all without the need for an additional hub. You can choose from 64+ patterns, including strobe, illusion, jump, energy, gradient, running, chasing, fluttering mode etc. Each mode can be applied to different scenes
  • 64+ Chasing IC+RGB & W Effect: The independent control design of IC+RGB and white all-in-one multifunctional rgbw led bar lights monitor backlight allows you to easily switch the led lights for desk between IC+RGB and white to enjoy a variety of lighting effects, you can choose white lighting mode with high brightness for better illumination when working, etc. Choose IC+RGB lighting mode when you need to create an entertaining atmosphere for the light show, 16 million colours of Color changing rgb light bar let you dance to the beat and create a dynamic party atmosphere
  • Dynamic and Dimmable Lights: 1%-full brightness free brightness adjustment gives you the flexibility to adjust dimmable led light bar for room decorations or a variety of occasions
  • USB Powered: USB light bars for room can be powered by powernank, usb charger, TV, Monitor, laptop PC mainframe, making behind TV led lighting bar easy to install in any location.TV led lights are powered by the TV usb interface / PC mainframe, can be turned on/off synchronously with TV / PC

9. Use debug logging only for stubborn cases

Normal access and error logs should be the first diagnostic tool. For a case that still does not reveal the mapping, Nginx debugging requires a binary built with --with-debug. Set error_log to debug in the relevant context, reproduce one controlled request, and inspect the resulting trace.

Debug logs can grow very large and affect performance. Restrict the duration and scope, protect the log files, and return to a normal logging level immediately after capturing the evidence you need. Do not leave debug logging enabled on a busy production server.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Common 404 scenarios and the correct fix

Symptom Likely cause First corrective action
A known file returns Nginx’s standard 404 page. The selected location resolves to the wrong directory, filename, or case. Calculate the root/alias path and verify the file and parent-directory access.
Every client-side route except the home page returns 404. No application-shell fallback is configured. Use an ordered try_files fallback to the shell file while preserving 404s for missing assets.
Static assets work, but API endpoints return 404. The proxy sends a prefixed or rewritten URI the backend does not serve. Compare the upstream request path with the application’s route definitions.
The backend log shows a 404 for the exact request. The application itself has no matching route or rejects the method. Fix application routing or adjust the proxy URI; do not add static files.
Changing a configuration file has no effect. The request selects another server block, Nginx instance, or configuration file. Confirm hostname/port matching, inspect the running configuration, validate, reload, and retest.
The custom error page also returns 404. The error_page target is missing or handled by an incompatible location. Verify the target file and its location mapping, then check for recursive error handling.

Additional pitfalls to rule out

A 404 that appears only for one URL variant is usually a mapping detail rather than a missing deployment. Compare the successful and failing requests character by character. A capitalized directory, a changed extension, or a slash that turns a file request into a directory request can select a different path or location. Test the canonical form your links generate, then test the alternate form deliberately so you know whether Nginx or the application is responsible for normalization.

Do not assume that a directory match means an index page exists. $uri/ in try_files only confirms a directory; the subsequent index handling still needs an actual index file. Conversely, removing the directory candidate can send a valid directory request to an application fallback unexpectedly. Keep file, directory, and application candidates in the order that matches the site’s routing design.

When an alias is involved, calculate the replacement manually for at least one failing URI and one working URI. The location prefix must be the portion you intend to replace, and the alias target must be the directory that contains the remainder. If the calculated path is correct but Nginx still reports a miss, use the error log to distinguish a nonexistent file from an access problem; changing root will not fix either issue unless the mapping itself is wrong.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Choosing between two valid fixes

Use the smallest change that matches the layer producing the response. A static file or server-rendered document belongs in the filesystem mapping; a browser-side route needs an application-shell fallback; and a backend endpoint needs a proxy path that matches an application route. Likewise, choose root when the URI should be appended to one document directory, and choose alias when a location prefix should be replaced by another directory. If both configurations could serve the same file, prefer the one that makes the URI-to-path relationship easiest to verify and maintain.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

For evidence, begin with ordinary access and error logs. Escalate to debug logging only when those logs do not show the selected mapping or upstream behavior. This limits performance impact while preserving a clear record of the change, reload, and retest that resolved the incident.

Final troubleshooting checklist

  • Identify whether Nginx or the upstream application generated the 404.
  • Confirm the hostname, port, protocol, and exact URI.
  • Find the selected server and most specific location.
  • Resolve the path using the actual root or alias semantics.
  • Check filename case, extension, trailing slash, and directory traversal permissions.
  • Read try_files candidates from left to right and verify the final fallback.
  • For a proxy, compare the URI sent upstream with a route the application serves.
  • Correlate Nginx access/error logs with the application log.
  • Validate the configuration, reload Nginx, and retest the exact URL plus relevant variants.
  • Configure error_page after routing is fixed, and use debug logging only briefly when ordinary logs are insufficient.

Frequently Asked Questions

Why does Nginx return 404 when the file exists?

The active server or location may resolve the URI somewhere other than the directory you checked. Calculate the path using the applicable root or alias, verify filename case and extension, and confirm that the worker can traverse every parent directory. The file may also be bypassed by a more specific location or an ordered try_files rule.

Best Value
Sale
HUANUO FlowLift™ Dual Monitor Stand, Fully Adjustable Gaming Monitor Desk Mount for 13–32″ Computer Screens, Full Motion VESA 75x75/100x100 with C-Clamp & Grommet Base, Each Arm Holds 4.4 to 19.8 lbs
  • Compatible with Wide Screens - To ensure compatibility with the dual monitor mount, your each monitor must meet three conditions at the same time: First, computer screens size range: 13 to 32 inches. Second, screen weight range: 4.4 to 19.8 lbs. Third, the back of the monitor screen must have VESA mounting holes with a pitch of 75x75mm or 100x100mm.
  • Regarding the compatibility with desks - Your desk must meet three conditions at the same time: First, desk material: Only wooden desks are recommended, plastic or glass desks cannot be used. Second, desk thickness range: 0.59" - 3.54". Third, the bottom of the desk should not have any cross beams or panels, as this will interfere with installation. We recommend carefully checking that your desk and monitors meets all above conditions before purchasing.
  • Dual C-Clamp Hold - Worried your dual monitors might wobble or slip? Our upgraded base uses a larger platform plus a dual C-clamp structure to lock the dual monitor arm firmly to your desk. Each arm safely keeps your screens steady while you type, click and game—no shaking, no sliding, just a clean and secure setup you can trust every day. It also provides Grommet Mounting installation choice, both options ensure stable and secure fixation for your 0.59" - 3.54" desk.
  • Full-Motion Adjustment For Comfortable View - Pull the screen closer when you’re deep in a spreadsheet, push it back to watch videos, or rotate to portrait for coding — moving everything smoothly with just one hand. The monitor stand offers +85°/-50° tilt, ±90° swivel and 360° rotation. Raise your monitor up to 15.75″ to support a healthy sitting posture. Whether you’re working from home, gaming through the night, or switching between video calls and documents, getting the screens to your natural line of sight helps relieve neck, shoulder and back strain so you can stay focused longer with less fatigue.
  • Keep Your Desk Organized: By lifting both screens off the desktop, this dual monitor stand opens up valuable space for your keyboard, notebook, docking station or a simple, clutter-free work area. Built-in cable management guides wires along the arms, keeping cords out of sight and out of the way. Enjoy a tidy, modern workstation that looks as good as it feels to use.

How can I tell whether Nginx or my application generated the 404?

Compare the response body and headers with Nginx access/error logs and the application log. A local lookup usually leaves an Nginx file-open error, while an upstream 404 appears in the application log with the path it received. If the request never reaches the application, fix Nginx mapping or proxying.

What is the difference between root and alias?

root appends the complete request URI to its directory. alias replaces the matching location prefix with its target directory. For example, location /assets/ { alias /srv/assets/; } maps /assets/app.css to /srv/assets/app.css.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Why do my single-page application routes return 404 after the home page works?

Those client-side routes may not have physical files. Use an ordered try_files fallback to the application shell, such as /index.html, while keeping missing asset requests able to return 404. Confirm that the fallback file exists under the selected root.

Why does my reverse proxy return 404 even though the upstream is running?

Reachability does not guarantee a valid route. Inspect the proxy_pass form and compare the exact URI sent upstream with the application’s route, including prefixes, version segments, and trailing slashes. Fix the application route or proxy URI rather than creating static files.

How do I safely apply an Nginx 404 fix?

Make one focused change, run the normal configuration test such as nginx -t, reload with nginx -s reload or your service manager, and request the exact failing URL again. Check logs after the reload and test trailing-slash, case, extension, and query-string variants.

Can I use a custom 404 page while troubleshooting?

Wait until normal routing works. With error_page 404 /404.html;, the target must exist and be handled by a location that does not return another 404. Otherwise the custom page can mask the original failure or create recursive error handling.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The Bottom Line

Trace the 404 to its source before changing anything: identify the selected server and location, calculate the root/alias path, follow try_files in order, and compare Nginx logs with the application log. Fix filesystem mapping locally and fix route or proxy-URI mismatches upstream. Validate, reload, retest the exact URL, and add custom error handling only after the underlying route works.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

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

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More quests from Patch Notes

  1. How to Set Up a RedM (RDR2) Server in 2026: License Key, txAdmin and server.cfg, Step by StepBlog11min
  2. Best RedM (RDR2) Server Hosting in 2026: Comparing Four Hosts on Slots, Memory and PriceBlog10min
  3. How to Host a Mindustry Server in 2026: server-release.jar, Port 6567 and the Commands That MatterBlog7min
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.