Halloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PCHalloween DealsAmazon USOctober picks are moving - compare before checkoutAmazon US: current deals, useful picks and tech finds.See Picks×
VGSOURCES
Get listed

404 errorsPATCH 2026.10.16

Nginx Location Block Returning 404: How to Fix It

By VGSources Team 10 min read

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

A 404 from an NGINX location block does not prove that the block is wrong. The request may be reaching a different server or location, resolving to the wrong filesystem path, missing an index file, hitting an intentional try_files ... =404, or being rejected by an upstream application or NGINX Ingress route. Fix it by tracing the request in that order: identify the selected server and location, calculate the path NGINX tests, verify index handling, inspect try_files fallbacks, and confirm that application routes are actually proxied.

Start with the request NGINX actually received

Before changing a directive, capture the complete request: scheme, host, listening port, URI, query string, and whether the URI ends with a slash. /app and /app/ are different URIs and can produce different behavior. A request sent to the wrong virtual host can also return a perfectly valid 404 from a completely different server {} block.

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.

Verify the server block

  • Check the Host header used by the client.
  • Confirm the request reached the intended listen port (for example, HTTP versus HTTPS).
  • For TLS, verify that the certificate and SNI name select the expected virtual host.
  • Test the exact URI, including its trailing slash and capitalization.

A useful local test is:

curl -i -H 'Host: example.com' http://127.0.0.1/app
curl -i -H 'Host: example.com' http://127.0.0.1/app/

Compare the status, Location header, response body, and any identifying headers. If the two requests differ, keep that distinction through the rest of the diagnosis.

Understand location precedence

NGINX compares the URI with all declared locations. An exact match has the highest priority for that URI. Otherwise, NGINX selects the longest matching prefix, then evaluates regular-expression locations; a matching regular expression can replace the chosen prefix unless the longest prefix uses ^~. This means a syntactically valid block may never process the request you had in mind.

#1 Best Overall
Sale
Gaoye Blue Light Blocking Glasses | Anti UV Ray, For Computers & Gaming, Square Frame, Eyewear for Men and Women
  • 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.
location = /game { ... }          # exact URI only
location /game/ { ... }           # prefix, including descendants
location ^~ /game/assets/ { ... } # longest prefix blocks regex takeover
location ~ .php$ { ... }         # regular expression

Use an exact location for one URI, a prefix for a tree of paths, and ^~ when a static subtree must not be intercepted by a regular expression. Inspect the active configuration, not only the file you edited:

nginx -T

Locate the relevant server_name, listen directive, and every candidate location. A reload without a configuration test can leave the old behavior in place, so validate first:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
nginx -t
nginx -s reload

Calculate the filesystem path produced by root or alias

Once you know which location handles the request, write down the disk path NGINX will test. Most “the file exists but NGINX says 404” incidents are mapping mistakes.

What root does

With root, NGINX appends the complete request URI to the configured directory. For example:

server {
    root /var/www/site;
    location /assets/ {
        # static handling
    }
}

A request for /assets/app.css is looked up as:

/var/www/site/assets/app.css

If the real file is /var/www/site/app.css, the configuration is looking in the wrong place. The file can be readable and still produce a 404 because NGINX is testing a different path.

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

When an alias-style mapping is appropriate

An alias-style mapping replaces the location prefix instead of appending the entire URI. To map /assets/app.css to /var/www/site/app.css, use a matching trailing slash on both the location and the alias:

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.
location /assets/ {
    alias /var/www/site/;
}

Under this mapping, /assets/ is replaced with /var/www/site/. Be deliberate with slashes: a missing or extra slash can change the resulting path, especially for nested requests. Do not switch from root to alias as a guess; first write the expected URI-to-disk conversion and make the directive match it.

Check the path after mapping

  • Confirm the file exists at the calculated path, not merely somewhere under the document root.
  • Check ownership and directory execute permission so the NGINX worker can traverse every parent directory.
  • Check case exactly; a path that works on a case-insensitive workstation may fail on a case-sensitive Linux filesystem.
  • Check symlink and mount permissions if the calculated path crosses a mounted volume.

The NGINX static-content guide states that when the requested file does not exist, NGINX returns HTTP 404 by default. That is normal behavior, not evidence of a broken location parser.

Handle directory requests and missing index files

A URI ending in / is treated as a directory request. NGINX then checks the filename configured by the index directive, commonly index.html in the documented example.

location /manual/ {
    root /var/www/site;
    index index.html;
}

For /manual/, NGINX tests the directory and then the configured index file, such as /var/www/site/manual/index.html. If that file is absent, the default result is 404. Verify the directory and index path before diagnosing location precedence.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
Sale
LISEN Cell Phone Stand Phone Holder for Desk, Office Decor Gadgets for Men | Office Gifts for Women, iPhone Stand, Gadgets for Men, Office Decor, Gaming Desk Accessories for Samsung Fold 8, Switch, iPad
  • 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)

Choose an intentional directory behavior

  • Add the expected index file at the calculated location.
  • Set index to the actual entry filename if the application uses another name.
  • Configure an application fallback when a directory URL belongs to a front controller.
  • Enable autoindex on only when a directory listing is intentionally public; it is not a general fix for a missing index.

Slash normalization matters when proxying as well. A slash-terminated prefix location can receive special redirect handling. Test both the slash and non-slash forms and decide which canonical URL your application should expose.

Read try_files as an ordered decision tree

try_files tests candidates in order and uses the final parameter as the action when none exists. The common configuration below deliberately returns 404:

location / {
    try_files $uri $uri/ =404;
}
  1. Test a file matching $uri.
  2. If that fails, test a directory matching $uri/.
  3. If neither exists, terminate the request with status 404 because =404 explicitly asks for that result.

Replacing the last parameter is a routing decision, not a cosmetic change.

Single-page application fallback

If the application uses one front-controller document, route misses to that document:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
location / {
    try_files $uri $uri/ /index.html;
}

Ensure /index.html is itself handled by a location with a valid mapping, and check for internal redirect loops. This pattern serves existing assets directly while allowing client-side routes such as /library/strategy to load the application shell.

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

Named fallback for an upstream app

When misses belong to a backend rather than a local file, use a named location:

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

location @backend {
    proxy_pass http://backend.example.com;
}

The named location must exist, and the backend must be reachable and configured to handle the original route. Confirm that the fallback does not redirect back into the same try_files block indefinitely.

Common try_files mistakes

  • Leaving =404 in a broad location / while expecting dynamic routes to reach an application.
  • Using a fallback URI that has no matching location.
  • Putting a directory candidate before an application fallback when the directory exists but has no usable index.
  • Assuming a successful static-file test means the upstream is healthy; the upstream may never have received the request.

Separate static files from application routes

A static location needs a correct root or alias-style mapping and an existing file. An application location needs a pass directive that sends the request to the application server. For HTTP upstreams, NGINX uses proxy_pass inside a location:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
location /api/ {
    proxy_pass http://backend.example.com;
}

The NGINX reverse-proxy documentation describes proxy_pass as the directive used inside a location to pass a request to an HTTP proxied server. Without it (or the appropriate FastCGI, uWSGI, or gRPC pass directive), NGINX will continue handling the request as local content and can return a local 404 before the application sees it.

Keep static matching narrow

A broad static block can intercept routes intended for the backend:

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.
location / {
    try_files $uri $uri/ =404;
}

location /api/ {
    proxy_pass http://backend.example.com;
}

Whether this works depends on location precedence and the exact URI. A request under /api/ should select the more specific application location. If a regular expression or another prefix takes precedence unexpectedly, add the appropriate exact or ^~ rule and verify with nginx -T. Another safe design is to reserve a clearly bounded static prefix such as /assets/ and proxy the application’s remaining paths.

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

NGINX Ingress adds a parent/subroute failure mode

In Kubernetes NGINX Ingress, path matching introduces another way to see a 404. A parent path can appear to match while no declared child path handles the requested resource. The documented example is a request for /static/fonts/bold.woff when the Ingress declares only child paths such as /static/css/ and /static/js/. The request can return 404 because the required font subroute was never declared.

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

Audit Ingress declarations

  • List every path the application must serve, including fonts, images, API prefixes, and health endpoints.
  • Declare the missing child route rather than assuming a parent automatically covers arbitrary descendants.
  • Keep the path type compatible with the parent. In the documented model, a ^~ parent requires compatible ^~ subroutes.
  • Inspect the generated NGINX configuration in the controller when the Kubernetes manifest and observed behavior disagree.

Test the Ingress hostname and path from outside the cluster, then compare controller logs with the application’s own access log. A 404 generated by the controller is different from a 404 returned by the backend.

Use logs to identify who generated the 404

After confirming the active configuration, issue a minimal request and follow it through the logs:

curl -i -H 'Host: example.com' http://127.0.0.1/assets/app.css
curl -i -H 'Host: example.com' http://127.0.0.1/assets/app.css/

Read access.log for the method, URI, status, and response size. Read error.log for the filesystem path NGINX attempted to open, permission errors, internal redirects, or upstream failures. The NGINX Beginner’s Guide recommends checking both logs when behavior is unexpected.

Distinguish local and upstream responses

  • A filesystem “not found” message points to the calculated root or alias path.
  • An internal redirect trace points to try_files, index processing, or a fallback loop.
  • An upstream status or connection error means the request reached (or tried to reach) the application; inspect that service’s route handling and logs.
  • No access-log entry on the expected server suggests a DNS, load-balancer, TLS, or virtual-host selection problem.

Use a temporary, carefully scoped log format with the host and URI if the existing logs do not identify the request. Remove diagnostic verbosity after the issue is resolved.

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

Match the symptom to the fix

Situation Correct focus Typical remedy
Wrong block selected Location precedence and server selection Adjust exact, prefix, regular-expression, ^~, or server_name rules
File path is wrong root/alias mapping and URI-to-disk calculation Correct the mapping, path, slash usage, ownership, or case
Directory has no index index directive and directory contents Add the index file or configure an intentional directory fallback
try_files ends in 404 Fallback semantics Replace =404 with a real fallback URI or named upstream location
Application route treated as static Upstream handoff Use proxy_pass or the application server’s pass directive
Ingress child route missing Parent and subroute declarations Add the route with a compatible path type

A repeatable repair procedure

  1. Record the failing request. Preserve the host, port, scheme, exact URI, trailing slash, method, and query string.
  2. Reproduce locally. Use curl -i with the intended Host header so DNS and browser caching do not obscure the result.
  3. Inspect the effective configuration. Run nginx -T and find the active virtual host plus all exact, prefix, and regex locations that could match.
  4. Determine the winning location. Apply exact, longest-prefix, regex, and ^~ precedence to the URI you recorded.
  5. Calculate the target. For root, append the URI; for alias-style mapping, replace the location prefix. Check the resulting file or directory directly.
  6. Check index processing. For a slash-terminated URI, verify the configured index filename and its location on disk.
  7. Expand try_files mentally. List each candidate in order and identify the final fallback action. Replace an intentional =404 only when the application has a defined fallback.
  8. Confirm the handoff. Dynamic routes require proxy_pass or the appropriate application pass directive; verify that the request appears in upstream logs.
  9. Audit Ingress paths if applicable. Add undeclared child routes and keep path types compatible.
  10. Validate and reload safely. Run nginx -t, reload, repeat both slash variants, and watch access and error logs for the new request.

Configuration examples that avoid the usual traps

Static assets in a separate directory

server {
    server_name example.com;

    location ^~ /assets/ {
        alias /var/www/site/;
    }

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

Here, /assets/app.css maps to /var/www/site/app.css, while other requests can fall back to the application shell. Confirm that the alias directory contains the files you expect and that /index.html is reachable through the same server.

Backend routes with a static fallback

server {
    server_name example.com;

    location ^~ /assets/ {
        root /var/www/site;
    }

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

    location @backend {
        proxy_pass http://backend.example.com;
    }
}

With the root example, /assets/app.css maps to /var/www/site/assets/app.css. Keep that layout only if the directory really contains an assets subdirectory; otherwise use the alias mapping shown above.

What not to assume

  • Do not assume every NGINX 404 is caused by root; server selection, precedence, index lookup, explicit try_files =404, upstream responses, and Ingress gaps are independent causes.
  • Do not assume adding a trailing slash fixes the mapping. It may select a different location or trigger directory/index processing.
  • Do not replace a 404 with a broad proxy rule until you know which requests are static and which belong to the application.
  • Do not infer success from a browser alone; browser redirects, cached responses, and service workers can hide the original request. Reproduce with curl and inspect logs.

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.

404 errorsKubernetes IngressNGINXReverse Proxyweb servers

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.

Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Outdated Drivers Are Slowing You DownFree scan - exact matches

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.