Wrong root path
- What nginx does
- Builds the file path by adding the request URI to the
rootvalue - Fix
- Point
rootat the directory that holds the files, then reload
Seeing 404 Not Found with nginx on the page? Check root versus alias, location matching, try_files and the error log to find why nginx cannot find the file.
A 404 Not Found from nginx means nginx matched the request to a location and could not find a file or route for that URL. The usual causes are a wrong root or alias path, a location block that catches the request, or a missing try_files fallback for single-page apps. Read the error log to see the path nginx tried.
Four quick questions, then a straight answer.
From your answers, this is quietly costing you traffic and nobody has the hours to chase it. Scaplet finds every affected page, drafts the fixes and tracks how AI answers mention you.
A data platform shipped 46 fixes without a ticket.
This looks handled. Re-check after a redesign, a migration or a big content push; that is when it breaks.
Your site is small and you have the time. Work through the steps on this page, starting with the pages that get the most traffic.
nginx can print its version on its own error pages, and the server_tokens directive controls that. If you proxy to an app server and the app returns its own 404, the page usually looks different, because nginx passes the upstream response along unless proxy_intercept_errors is on (it is off by default). That difference decides where to dig. The general meaning of the status code is on the 404 Not Found page.
Run curl -si https://example.com/page and compare the headers and body with the same request sent straight to the upstream. If the upstream answers 200 and nginx answers 404, the problem is in the nginx configuration. If both return 404, fix the app or its routes.
root pathroot valueroot at the directory that holds the files, then reloadalias used where root fitsroot when the location matches the last part of the directory pathtry_files fallback for a single-page apptry_files with an internal redirect to /index.htmllocation catches the requestinternalinternal or route requests through the intended redirectproxy_intercept_errors is off by default)proxy_pass URIThe nginx reference spells out how a path is built: with root /data/w3; inside location /i/, the request /i/top.gif is served from /data/w3/i/top.gif. With alias /data/w3/images/; in the same location, it is served from /data/w3/images/top.gif. Mix them up and nginx looks in the wrong directory.
server {
root /var/www/app;
location / {
try_files $uri $uri/ /index.html;
}
}try_files checks for files in the order given and uses the first one found. If none exists, it makes an internal redirect to the last parameter. The last parameter can also be a status code such as =404, which sends that code on purpose.
nginx -t checks syntax and tries to open the files the config refers to. nginx -T does the same and also prints the configuration, so you see which server and location blocks nginx really loaded.
The default is error_log logs/error.log error;, though packages often move it. The error level and above are logged, which includes file-not-found problems unless log_not_found is off.
It defaults to on. If someone switched it off, missing files will not appear in the error log, which makes a 404 look unexplained.
Join the root value and the request URI by hand and look for that file. Compare the filename character for character, including case.
Run nginx -s reload after a change, then repeat the same curl request.
To Google, an nginx 404 is the same as any other 404: the URL is not indexed, and an indexed URL that starts returning it is removed. The risk is a configuration mistake that returns 404 for pages that should exist, such as a deploy that changes root. Watch Search Console after config changes. See 4xx errors for the audit steps.
4 questions people ask next, answered from the sources on this page.
The request reached an nginx server that found nothing for that URL. nginx's own error pages can include its version, which server_tokens controls. The page says nothing about your browser.
The default is the error_log directive, logs/error.log at the error level, but many packages set a different path. Run nginx -T and search the output for error_log to find yours.
root appends the whole request URI to its path. alias replaces the matched location part with its path. Use root where the location matches the end of the directory path, as the nginx docs advise.
End try_files with /index.html, as in the snippet above, so nginx falls back to the app shell for routes that are not real files. The app's router then handles the path.
Run the free audit, then approve the fixes. Every change can be undone.