error_page 404 /404.html;
- What the docs say
- Internal redirect to the URI
- SEO effect
- Keep this. Test that the status is still 404.
Set a custom 404 page in nginx with error_page, keep the real 404 status, and avoid the soft 404 errors Google flags when an error page returns 200.
Add error_page 404 /404.html; to your server block and put the page at that URI. Nginx does an internal redirect to it. Don't write 404 =200, because that changes the response code to 200, and Google treats a not-found page served with a 200 as a soft 404.
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.
error_page directive defines the URI shown for the specified errors. It works in the http, server and location contexts, and in if inside location. Nginx's docs say it causes an internal redirect to the URI you give, with the request method changed to GET for all methods other than GET and HEAD. The docs describe URL redirects as a separate form of the directive (see the table below).The location = /404.html block is optional but tidy. The = modifier matches that exact URI, and internal means outside requests for /404.html get a 404 from nginx instead of serving the error page directly. Put 404.html in the root directory, and any CSS or images it uses need to be reachable too.
Reload after editing: nginx -t tests the configuration file for correct syntax, and nginx -s reload makes the master process check the new configuration and apply it.
server {
listen 80;
server_name example.com;
root /var/www/example.com;
error_page 404 /404.html;
location = /404.html {
internal;
}
}=response syntax, as in error_page 404 =200 /empty.gif;. Leave that part out and you are not asking for a different code, which is what you want for SEO. Test it with curl -I rather than assuming.error_page 404 /404.html;error_page 404 =200 /404.html;error_page 404 = /404.php;error_page 404 =301 http://example.com/notfound.html;error_page 404 http://example.com/notfound.html;Google defines a soft 404 as a URL that returns a page telling the user the page does not exist and also a 200 (success) status code. Its fix for content that is gone is a 404 or 410, and a 301 when the content moved. Read the soft 404 glossary entry and the soft 404 errors issue for how to find them.
error_page 404 = /404.php; responds with whatever code the FastCGI, uwsgi, SCGI, gRPC or proxied server returns. A named location passes error handling on without changing the URI or method.Whichever you pick, check what the app sends. If it returns its own 'not found' page with a 200, nginx will pass the 200 along.
location / {
error_page 404 = @fallback;
}
location @fallback {
proxy_pass http://backend;
} error_page directives are inherited from the previous level only if the current level defines none. Adding one error_page in a location drops the ones from server.
nginx limits internal redirects to 10 per request. Past that it returns a 500, and the error log shows 'rewrite or internal redirection cycle'. The docs say this guards against incorrect configurations.
the docs say that if processing the URI leads to an error, the status code of the last occurred error is returned to the client.
Google says custom 404 pages are useless from a search engine's perspective, so make sure the server returns a 404 status code to prevent having them indexed.
For error-page basics beyond nginx, see the Django 404 guide and the 4xx errors issue.
Run curl -I https://example.com/no-such-page and confirm the first line shows 404.
Run curl -I https://example.com/404.html. With internal set it should return 404 too, which is correct for outside requests.
Watch the Page indexing report for soft 404 entries after the change.
4 questions people ask next, answered from the sources on this page.
Add error_page 404 /404.html; to the server block, put 404.html in the site root, then run nginx -t and reload. Nginx does an internal redirect to that URI.
Yes, unless you change it. The docs show the =response syntax for changing the code, such as error_page 404 =200 /empty.gif;. Leave it out and test with curl -I.
Most often the code was changed to 200 with =200, or an app behind nginx returns its own not-found page with 200. Google defines a soft 404 as a not-found page that returns a 200 status code.
It limits a location to internal requests. For external requests, nginx returns a 404 (Not Found). Requests redirected by error_page count as internal.
Run the free audit, then approve the fixes. Every change can be undone.