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

Canonical: https://scaplet.com/seo/nginx/404

Guide Nginx Nginx · Error pages

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 with [ChatGPT](https://chatgpt.com/?hints=search&q=Summarize%20https%3A%2F%2Fscaplet.com%2Fseo%2Fnginx%2F404%20(%22Nginx%20custom%20404%20page%22)%20in%205%20bullet%20points%2C%20then%20tell%20me%20the%20one%20thing%20I%20should%20do%20next.) [Claude](https://claude.ai/new?q=Summarize%20https%3A%2F%2Fscaplet.com%2Fseo%2Fnginx%2F404%20(%22Nginx%20custom%20404%20page%22)%20in%205%20bullet%20points%2C%20then%20tell%20me%20the%20one%20thing%20I%20should%20do%20next.) [Perplexity](https://www.perplexity.ai/search?q=Summarize%20https%3A%2F%2Fscaplet.com%2Fseo%2Fnginx%2F404%20(%22Nginx%20custom%20404%20page%22)%20in%205%20bullet%20points%2C%20then%20tell%20me%20the%20one%20thing%20I%20should%20do%20next.) [![Google](/logos/ai/google-color.svg)AI Mode](https://www.google.com/search?udm=50&q=Summarize%20https%3A%2F%2Fscaplet.com%2Fseo%2Fnginx%2F404%20(%22Nginx%20custom%20404%20page%22)%20in%205%20bullet%20points%2C%20then%20tell%20me%20the%20one%20thing%20I%20should%20do%20next.)

On this page

## 5 parts, 4 minutes.

1. [The minimum config for a custom 404 page 01](#the-minimum-config-for-a-custom-404-page)
2. [Keep the status code a real 404 02](#keep-the-status-code-a-real-404)
3. [Proxied and FastCGI apps 03](#proxied-and-fastcgi-apps)
4. [Gotchas 04](#gotchas)
5. [Test it in two minutes 05](#test-it-in-two-minutes)

_01_Check 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; } }
```

_02_error_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](/glossary/http-status-codes) to 200

SEO effect

[Soft 404](/glossary/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](/glossary/soft-404) and the [soft 404 errors](/seo-issues/soft-404-errors) issue for how to find them.

**Don't redirect every 404 to the home page**A redirect to `/` or to another URL returns a 3xx for a URL that has no replacement. Google's fix for removed content with no replacement is a 404 or 410. Keep redirects for URLs that actually moved.

_03_Check 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; }
```

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

_05_How it works

## Test it in two minutes

For error-page basics beyond nginx, see the [Django 404 guide](/seo/django/404) and the [4xx errors](/seo-issues/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](/glossary/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.

_01_ How 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.

_02_ Does 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`.

_03_ Why 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.

_04_ What 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. 01 [Module ngx_http_core_module: error_page, internal, location, root | nginx documentation](https://nginx.org/en/docs/http/ngx_http_core_module.html) nginx.org · checked 2026-10-25
2. 02 [Command-line parameters | nginx documentation](https://nginx.org/en/docs/switches.html) nginx.org · checked 2026-10-25
3. 03 [Beginner's Guide (reloading configuration) | nginx documentation](https://nginx.org/en/docs/beginners_guide.html) nginx.org · checked 2026-10-25
4. 04 [Troubleshoot Google Search crawling errors | Google Search Central](https://developers.google.com/search/docs/crawling-indexing/troubleshoot-crawling-errors) developers.google.com · checked 2026-10-25
5. 05 [How HTTP status codes affect Google's crawlers | Google Crawling Infrastructure](https://developers.google.com/crawling/docs/troubleshooting/http-status-codes) developers.google.com · checked 2026-10-25

## Keep learning

[All platform guides](/seo)

[Learn Django custom 404 page Frameworks](/seo/django/404) [Related HTTP status codes Crawling and indexing](/glossary/http-status-codes) [Read next Next.js 404 page Frameworks](/seo/nextjs/404) [Do Run a free site audit Free, about two minutes](/site-audit)

Nearby in platform guides
[Next.js title and meta description](/seo/nextjs/title-and-meta) [Next.js XML sitemap](/seo/nextjs/xml-sitemap) [Nuxt SEO](/seo/nuxt) [Nuxt redirects](/seo/nuxt/redirects)

Terms on this page
[HTTP status codes](/glossary/http-status-codes) [Soft 404](/glossary/soft-404) [Page indexing report](/glossary/page-indexing-report)

Free · 2 minutes

## Tools point. Agencies advise. _This one ships._

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

[Audit my site free](/site-audit)

Free, no card 60 seconds Nobody will call you

- **46** fixes shipped without a ticket Brightpipe
- **0→7** ChatGPT citations in six weeks Paylane
