Free auditStart free
GuideNginx · Error pages

Nginx custom 404 page

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.

4 min
read
5
sources
Oct 22, 2026
updated
Scaplet Editorial Team
author
In one line

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.

30-second check

Where does your site stand?

Four quick questions, then a straight answer.

1/4Have you checked your own site for this?
Summarize this page withChatGPTClaudePerplexityGoogleAI Mode
01Check it

The minimum config for a custom 404 page

The 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.

/etc/nginx/conf.d/example.conf
server {
    listen 80;
    server_name example.com;
    root /var/www/example.com;

    error_page 404 /404.html;

    location = /404.html {
        internal;
    }
}
02error_page forms and what they do

Keep the status code a real 404

Nginx's docs show how to change the code: the =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.
Directive

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.
Directive

error_page 404 =200 /404.html;

What the docs say
Changes the response code to 200
SEO effect
Soft 404. Avoid.
Directive

error_page 404 = /404.php;

What the docs say
Responds with the code the FastCGI or proxied server returns
SEO effect
Fine, if your app returns 404 itself.
Directive

error_page 404 =301 http://example.com/notfound.html;

What the docs say
URL redirect, code can only be 301, 302, 303, 307 or 308
SEO effect
Sends crawlers to another URL. Not a real 404 page.
Directive

error_page 404 http://example.com/notfound.html;

What the docs say
URL redirect, 302 by default
SEO effect
Avoid for missing pages.

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.

03Check it

Proxied and FastCGI apps

If nginx fronts an app and the app should decide what a 404 looks like, the docs give two patterns. 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.

Named location
location / {
    error_page 404 = @fallback;
}

location @fallback {
    proxy_pass http://backend;
}
04Worth knowing

Gotchas

Inheritance

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.

Loops

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.

Errors in the error page

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.

Don't index the error page itself

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.

05How it works

Test it in two minutes

For error-page basics beyond nginx, see the Django 404 guide and the 4xx errors issue.

  1. 01

    Request a missing URL

    Run curl -I https://example.com/no-such-page and confirm the first line shows 404.

  2. 02

    Check the error page file

    Run curl -I https://example.com/404.html. With internal set it should return 404 too, which is correct for outside requests.

  3. 03

    Check Search Console

    Watch the Page indexing report for soft 404 entries after the change.

Questions

Asked a lot.

4 questions people ask next, answered from the sources on this page.

01How do I set a custom 404 page in nginx?

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.

02Does the nginx custom 404 page return a 404 status?

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.

03Why is my nginx 404 page a soft 404?

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.

04What does the internal directive do?

It limits a location to internal requests. For external requests, nginx returns a 404 (Not Found). Requests redirected by error_page count as internal.

Sources · 5

Every fact, linked and dated.

Official docs first. The date is when we last opened each page.
  • nginx.org
  • google.com
  1. 01Module ngx_http_core_module: error_page, internal, location, root | nginx documentationnginx.org · checked 2026-10-25
  2. 02Command-line parameters | nginx documentationnginx.org · checked 2026-10-25
  3. 03Beginner's Guide (reloading configuration) | nginx documentationnginx.org · checked 2026-10-25
  4. 04Troubleshoot Google Search crawling errors | Google Search Centraldevelopers.google.com · checked 2026-10-25
  5. 05How HTTP status codes affect Google's crawlers | Google Crawling Infrastructuredevelopers.google.com · checked 2026-10-25
Free · 2 minutes

Tools point. Agencies advise. This one ships.

Run the free audit, then approve the fixes. Every change can be undone.

Free, no card60 secondsNobody will call you
  • 46 fixes shipped without a ticket Brightpipe
  • 0→7 ChatGPT citations in six weeks Paylane