HTTP 405 Method Not Allowed
405 means the URL exists but doesn't accept that HTTP method, for example DELETE /users when the collection only supports GET and POST.
405 Method Not Allowed
The method is known to the server but not supported by the target resource.
Who fixes it: Either side. Either the client used the wrong method, or the server routes the request to something that doesn't handle it (often a static file handler).
What 405 means
RFC 9110 requires the server to send an Allow header listing the methods the resource does support, so a 405 is self-documenting: the client can read Allow: GET, POST and fix its request.
Don't confuse it with 501 Not Implemented, which means the server doesn't support the method for any resource at all.
Source: RFC 9110 §15.5.6.
Common causes
- A form or
fetch()posting to a static file. nginx serves static files only for GET and HEAD, soPOST /index.htmlgets405 Not Allowed. It happens when an API request misses the proxylocationand falls through to the static root. - Next.js App Router:
route.tsdoesn't export a function for that method, e.g. onlyGETis exported and the client sendsPOST. Next.js responds 405 automatically. - CORS preflight: the browser sends
OPTIONSbefore a cross-originPUT,DELETEor JSONPOST. If nothing handlesOPTIONS, some frameworks return 405 and the browser reports a CORS error. - A redirect changed the method: a
POSTthat gets a 301 or 302 (often a trailing-slash redirect) is re-sent asGET, which may not be allowed at the target. - The wrong method by mistake:
PUTvsPATCH, orGETto a search endpoint that only takesPOST. - IIS: the WebDAV module intercepts
PUTandDELETEand returns 405 before your ASP.NET app sees them.
How to fix a 405
Ask the server what it allows
The Allow header on the 405 lists the supported methods. Some servers also answer OPTIONS with it.
curl -i -X DELETE https://api.example.com/users
HTTP/2 405
allow: GET, POST
curl -i -X OPTIONS https://api.example.com/usersnginx: make sure API calls reach the app
If a POST gets nginx's own 405 Not Allowed page, it was handled as a static file. Check that the URL matches the proxy location, including the trailing slash.
location /api/ {
proxy_pass http://127.0.0.1:3000;
}
location / {
root /var/www/app/dist;
try_files $uri $uri/ /index.html;
}Next.js Route Handlers
Export one function per method you support. Anything else gets a 405.
// app/api/items/route.ts
export async function GET() {
return Response.json(await listItems());
}
export async function POST(request: Request) {
const item = await createItem(await request.json());
return Response.json(item, { status: 201 });
}
// No DELETE export: DELETE /api/items returns 405Express: send a proper 405
Express returns 404 for unsupported methods by default. router.route() with a final .all() gives you a correct 405 with Allow. Express answers HEAD for any GET route, so include it.
app.route('/api/items')
.get(listItems)
.post(createItem)
.all((req, res) => {
res.set('Allow', 'GET, HEAD, POST');
res.status(405).json({ error: 'method_not_allowed' });
});Headers that matter with 405
- Allow
- Required in a 405. An empty value is valid and means the resource currently allows no methods, e.g. when it's disabled by configuration.
- Access-Control-Allow-Methods
- The CORS equivalent for preflight responses. Missing methods here cause browser CORS errors, not a 405.
405 vs similar status codes
- 404 Not Found: Nothing at the URL at all. Express uses 404 where 405 would be more accurate.
- 501 Not Implemented: The server doesn't recognise or support the method for any resource.
- 403 Forbidden: The method is supported, but this client isn't allowed to use it.
Related status codes
404Not Found
The server has no current representation of the target resource, or won't say whether one exists.
400Bad Request
The server can't or won't process the request because of something it considers a client error.
403Forbidden
The server understood the request but refuses to fulfil it.
Looking for another code? Search the full HTTP status codes list, or read which code your API should return in the REST API status codes guide.
Learn more
HTTP Status Codes for REST APIs: 200 vs 201 vs 204, 400 vs 422 vs 429
A practical guide to choosing the right HTTP status code in REST API design. Covers the most confusing pairs: 200 vs 201, 400 vs 422, 401 vs 403, and when to use 503 vs 429.
REST API Design Best Practices: A Practical Guide
The conventions that make REST APIs intuitive and consistent. Covers URL design, HTTP methods, status codes, versioning, pagination, and error responses.
CORS Explained: Why It Happens and How to Fix It
CORS errors happen when a browser blocks a request to a different origin. Learn how the Same-Origin Policy works, what preflight requests are, and how to configure CORS correctly in Express, FastAPI, and Nginx.
Frequently Asked Questions
What is the difference between 405 and 404?▾
404 means nothing exists at that URL. 405 means the URL exists but doesn't accept the method you used. Express is a common source of confusion: it returns 404 with Cannot POST /path for an unsupported method unless you add a 405 handler.
Why does nginx return 405 Not Allowed for my POST request?▾
nginx's static file handler only supports GET and HEAD. A POST that lands in a location serving files, instead of being proxied to your app, gets a 405. Check that the URL matches your proxy_pass location, including trailing slashes.
Does a 405 response need an Allow header?▾
Yes. RFC 9110 says the origin server must send Allow with the methods the resource currently supports. An empty Allow header is valid and means no methods are currently allowed.