HTTP 405 · 4XX RFC 9110 §15.5.6 Cacheable: Yes (by default) Retryable: No (change HTTP method)

HTTP 405 Method Not Allowed: Root Causes & Production Fix Guide

HTTP 405 Method Not Allowed occurs when the target URL exists but rejects the HTTP verb (such as sending POST to a static Nginx asset or OPTIONS to a backend without CORS preflight handling).

Top Root Causes of HTTP 405

Nginx Allow OPTIONS Preflight & Route POST to Upstream

location /api/submit {
    if ($request_method = 'OPTIONS') {
        add_header Access-Control-Allow-Origin "https://app.example.com" always;
        add_header Access-Control-Allow-Methods "POST, OPTIONS" always;
        add_header Access-Control-Allow-Headers "Content-Type, Authorization" always;
        return 204;
    }
    proxy_pass http://127.0.0.1:8080;
}

Verify with cURL

curl -i -sS -X OPTIONS https://api.example.com/api/submit

Interactive Stack Diagnoser (HTTP 405)

Frequently Asked Questions

What header must accompany a 405 Method Not Allowed response?

RFC 9110 requires an `Allow` header listing supported methods, for example `Allow: GET, HEAD, POST`.

Why does Nginx return 405 Not Allowed on POST requests?

Nginx forbids POST requests to static files. Verify your `location` regex matches the API path and forwards it with `proxy_pass`.

How do I fix 405 on CORS preflight?

Handle `OPTIONS` at your API middleware or reverse proxy and return 204 No Content with the proper `Access-Control-Allow-*` headers.

Related Status Guides & Header Tools