Free auditStart free
GuideError · HTTP status codes

405 Not Allowed in nginx

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
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
  2. Reproduce it
  3. Fixes
  4. 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 withChatGPTClaudePerplexityGoogleAI Mode
02How 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.

03Fix it on your stack

Fixes

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
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)
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. Use it for a thank-you page, not for form handling, since the POST body is discarded.

Other causes
CauseFix
WebDAV or API client uses PUT, DELETE, MKCOL, COPY, MOVEBuild nginx with --with-http_dav_module and set dav_methods; the module is not built by default
Proxied app returns 405The method or route is wrong in the app; nginx passes it on. proxy_method can change the method sent upstream
Method restricted with limit_exceptReview 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
04Explained

SEO and crawler notes

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 for the general status and 405 in 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. 01RFC 9110: HTTP Semanticsrfc-editor.org · checked 2026-11-01
  2. 02nginx: ngx_http_core_module (error_page, limit_except)nginx.org · checked 2026-11-01
  3. 03nginx: ngx_http_dav_modulenginx.org · checked 2026-11-01
  4. 04nginx: ngx_http_proxy_module (proxy_method)nginx.org · checked 2026-11-01
  5. 05nginx source: ngx_http_static_module.craw.githubusercontent.com · checked 2026-11-01
  6. 06nginx source: ngx_http_request.craw.githubusercontent.com · checked 2026-11-01
  7. 07nginx source: ngx_http_special_response.craw.githubusercontent.com · checked 2026-11-01
  8. 08How HTTP status codes affect Google's crawlersdevelopers.google.com · checked 2026-11-01
Questions

Asked a lot.

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

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

02How 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;.

03Does 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.

Free · 2 minutes

Tools point. Agencies advise. This one ships.

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

Free, no card60 secondsNobody will call you
  • 46 fixes shipped without a ticket Brightpipe
  • 0→7 ChatGPT citations in six weeks Paylane