# 405 Not Allowed in nginx

> Fix an nginx 405 Not Allowed: why POST to a static file fails, which methods nginx

Canonical: https://scaplet.com/errors/http/405/nginx

Guide Error · HTTP status codes

Fix an nginx 405 Not Allowed: why POST to a static file fails, which methods nginx's static handler accepts, and the proxy, WebDAV and error_page options.

3 min

read

8

sources

Oct 30, 2026

updated

Scaplet Editorial Team

author

405 4xx · Client error

The short answer

nginx returns `405 Not Allowed` when a request method is not accepted for the resource. The classic case is a POST to a static file: nginx's static handler serves GET, HEAD and POST requests but returns 405 for a POST to an existing file, and for any other method. Route the method to an app with `proxy_pass` or `fastcgi_pass`, or enable the right module.

1. [What nginx is doing](#what-nginx-is-doing)
2. [Reproduce it](#reproduce-it)
3. [Fixes](#fixes)
4. [SEO and crawler notes](#seo-and-crawler-notes)

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%2Ferrors%2Fhttp%2F405%2Fnginx%20(%22405%20Not%20Allowed%20in%20nginx%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%2Ferrors%2Fhttp%2F405%2Fnginx%20(%22405%20Not%20Allowed%20in%20nginx%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%2Ferrors%2Fhttp%2F405%2Fnginx%20(%22405%20Not%20Allowed%20in%20nginx%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%2Ferrors%2Fhttp%2F405%2Fnginx%20(%22405%20Not%20Allowed%20in%20nginx%22)%20in%205%20bullet%20points%2C%20then%20tell%20me%20the%20one%20thing%20I%20should%20do%20next.)

_01_When nginx's own code returns 405

## What nginx is doing

RFC 9110 defines 405 as: the method "received in the request-line is known by the origin server but not supported by the target resource", and the server "MUST generate an Allow header field". nginx's own error page reads `405 Not Allowed`. In the nginx source, the static file handler returns 405 in three situations.

Request

### `POST` to an existing static file

Result

405

Source behavior

The static module returns not allowed for POST once the file is found

Request

### `PUT`, `DELETE`, `PATCH`, anything but GET, HEAD, POST

Result

405

Source behavior

Static handler accepts only those three methods

Request

### `POST` to a file that does not exist

Result

404

Source behavior

The file lookup fails first

Request

### `TRACE`

Result

405

Source behavior

Logged as `client sent TRACE method`

Request

### `CONNECT` unless allowed

Result

405

Source behavior

Logged as `client sent CONNECT method`

So a form that posts to `/contact.html` fails even though the file is there. The fix is almost always to send that POST to an application, not to serve it as a file.

_02_How it works

## Reproduce it

Compare methods on the same URL

```
curl -i -X GET https://example.com/contact.html # 200 curl -i -X POST https://example.com/contact.html # 405 Not Allowed curl -i -X OPTIONS https://example.com/contact.html curl -i -X TRACE https://example.com/ # 405
```

1. 01

### Read the status line and body

A body titled `405 Not Allowed` with `Server: nginx` came from nginx itself. A 405 with another body came from your app, passed through.
2. 02

### Look for Allow

The RFC requires an `Allow` header on a 405. Check the response; if one is present, it lists the methods the resource accepts.
3. 03

### Find the matching location

Run `nginx -T` and find which `location` handles the URL. If it ends at a `root` with no `proxy_pass`, nginx is serving a file.

_03_Fix it on your stack

## Fixes

Send dynamic endpoints to the app
Send dynamic endpoints to the app

```
location /api/ { proxy_pass http://127.0.0.1:8000; proxy_set_header Host $host; } location / { root /var/www/site; try_files $uri $uri/ =404; }
```

PHP forms: pass .php to FastCGI instead of serving it
PHP forms: pass .php to FastCGI instead of serving it

```
location ~ \.php$ { include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_pass unix:/run/php/php-fpm.sock; }
```

Stopgap: answer POST to one static page with the page (200)
Stopgap: answer POST to one static page with the page (200)

```
location = /thanks.html { error_page 405 =200 $uri; }
```

The stopgap works because of how `error_page` behaves: the internal redirect changes the client request method to `GET` for methods other than `GET` and `HEAD`, and `=200` changes the [response code](/glossary/http-status-codes). Use it for a thank-you page, not for form handling, since the POST body is discarded.

Other causes
| Cause | Fix |
| WebDAV or API client uses PUT, DELETE, MKCOL, COPY, MOVE | Build nginx with `--with-http_dav_module` and set `dav_methods`; the module is not built by default |
| Proxied app returns 405 | The method or route is wrong in the app; nginx passes it on. `proxy_method` can change the method sent upstream |
| Method restricted with `limit_except` | Review the block; allowing GET also allows HEAD |

Use proxy_pass when
- The URL is an endpoint that should process POST
- You already run an app server
- You need the request body

Use the error_page stopgap when
- The URL is a static confirmation page
- Nothing needs the POST body
- You cannot change the client

_04_Explained

## SEO and crawler notes

[Googlebot](/ai-crawlers/googlebot) fetches with GET, which the static handler allows, so a 405 on POST does not block crawling. But Google treats 4xx other than 429 as content that does not exist, so a GET-able page that returns 405 for GET will be dropped from the index over time. Test `curl -I` as well as POST. See [405 Method Not Allowed](/errors/http/405) for the general status and [405 in Apache](/errors/http/405/apache) for the Apache side.

Sources · 8

## Every fact, linked and dated.

Official docs first. The date is when we last opened each page.

- rfc-editor.org
- nginx.org
- githubusercontent.com
- google.com

1. 01 [RFC 9110: HTTP Semantics](https://www.rfc-editor.org/rfc/rfc9110.html) rfc-editor.org · checked 2026-11-01
2. 02 [nginx: ngx_http_core_module (error_page, limit_except)](https://nginx.org/en/docs/http/ngx_http_core_module.html) nginx.org · checked 2026-11-01
3. 03 [nginx: ngx_http_dav_module](https://nginx.org/en/docs/http/ngx_http_dav_module.html) nginx.org · checked 2026-11-01
4. 04 [nginx: ngx_http_proxy_module (proxy_method)](https://nginx.org/en/docs/http/ngx_http_proxy_module.html) nginx.org · checked 2026-11-01
5. 05 [nginx source: ngx_http_static_module.c](https://raw.githubusercontent.com/nginx/nginx/master/src/http/modules/ngx_http_static_module.c) raw.githubusercontent.com · checked 2026-11-01
6. 06 [nginx source: ngx_http_request.c](https://raw.githubusercontent.com/nginx/nginx/master/src/http/ngx_http_request.c) raw.githubusercontent.com · checked 2026-11-01
7. 07 [nginx source: ngx_http_special_response.c](https://raw.githubusercontent.com/nginx/nginx/master/src/http/ngx_http_special_response.c) raw.githubusercontent.com · checked 2026-11-01
8. 08 [How HTTP status codes affect Google's crawlers](https://developers.google.com/crawling/docs/troubleshooting/http-status-codes) developers.google.com · checked 2026-11-01

Questions

## Asked a lot.

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

_01_ Why does nginx return 405 for POST to an HTML file?

nginx's static handler allows GET, HEAD and POST requests, but returns 405 when a POST targets an existing regular file. Send the POST to an application with `proxy_pass` or `fastcgi_pass`.

_02_ How do I fix nginx 405 Not Allowed?

Find the `location` serving the URL. If it serves files, route that path to your app. For a static thank-you page you can use `error_page 405 =200 $uri;`.

_03_ Does nginx send an Allow header with 405?

RFC 9110 says the origin server MUST generate one, but check your own response with `curl -i`. nginx's documentation does not describe it, so verify rather than assume.

## Keep learning

[All errors](/errors)

[Learn HTTP 405 Method Not Allowed HTTP status codes](/errors/http/405) [Related 4xx errors Status codes and links](/seo-issues/4xx-errors) [Read next 405 Method Not Allowed in Apache HTTP status codes](/errors/http/405/apache) [Do Run a free site audit Free, about two minutes](/site-audit)

Other 405 errors
[405 Method Not Allowed in Apache](/errors/http/405/apache) [HTTP 405 Method Not Allowed](/errors/http/405)

Nearby in errors
[406 Not Acceptable](/errors/http/406) [HTTP 407 Proxy Authentication Required](/errors/http/407)

More in HTTP 405 Method Not Allowed
[405 Method Not Allowed in Apache](/errors/http/405/apache) [405 Not Allowed in nginx](/errors/http/405/nginx)

Terms on this page
[HTTP status codes](/glossary/http-status-codes)

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
