Skip to content

Troubleshooting guide

405 Method Not Allowed: why it happens and how to fix it

A 405 means the URL exists, but it does not accept the HTTP method you used. Usually a POST or PUT reached something that only serves GET.

4 min read10 sectionsUpdated

On this page

Key points

  • The Allow response header lists the methods that URL accepts.
  • POST to a static file is the classic Nginx 405.
  • A redirect can silently convert POST into GET, so the method that arrives differs from the one sent.
  • OPTIONS returning 405 is really a CORS preflight failure.

What 405 means

The server recognised the resource but not the verb. That makes 405 more useful than 404: routing found something, so the path is at least close. A correct response carries an Allow header naming the supported methods.

Common causes

  • The request reached the wrong backend. Nginx serving static files rejects POST with 405, which usually means location matching did not send the request to your application.
  • A redirect changed the method. A 301 or 302, often from HTTP to HTTPS or for a trailing slash, leads many clients to retry with GET. The server then rejects a GET on a POST-only route.
  • A missing route handler. The application defines GET for a path and the client sends PUT.
  • CORS preflight. The browser sends OPTIONS first, and the server does not handle it.
  • A security rule on IIS or a WAF that disables PUT and DELETE.

Diagnose it

Ask the server what it allows, then send the actual method without following redirects, so you can see any hidden 30x.

bash
# Which methods does this URL allow?
curl -si -X OPTIONS https://api.example.com/items | grep -iE '^(HTTP|allow|access-control)'

# Send the real method and do NOT follow redirects
curl -si -X POST https://api.example.com/items -d '{}' | head -12

# Does a slash change the answer?
curl -s -o /dev/null -w "%{http_code} %{redirect_url}\n" -X POST https://api.example.com/items/

Fixes

If a redirect is involved, call the final URL directly, and use 307 or 308 on the server, because those status codes require clients to keep the method. If Nginx is answering, fix the location block so requests reach proxy_pass. For CORS, handle OPTIONS at the proxy or framework level and return the allowed methods and headers. If a route is missing, confirm that the deployed version of the code actually includes it.

Catch it automatically

A 405 after a release usually means a client and server were deployed out of step. A multi-step API check that sends the real method and asserts the status catches this where a GET-only check never would. In APM, a route that moves suddenly from 2xx to 405 is a clear deployment marker.

Frequently asked questions

What is the difference between 404 and 405?

404 means nothing exists at that URL. 405 means something exists but it does not support the HTTP method used.

Why is my POST turning into a GET?

A 301 or 302 redirect makes many clients repeat the request with GET. Call the final URL directly, or use 307 or 308 redirects, which preserve the method.

Why do I get 405 on OPTIONS?

That is a CORS preflight the server does not handle. Add OPTIONS handling that returns the allowed origins, methods and headers.

Check it now, free

Watch your own site and services with VitalRix

Uptime checks, APM, logs, real-user monitoring, alerts and status pages in one place. Every product has a free tier and no credit card is needed.