VPS Tutorials
How to Fix Nginx 405 Method Not Allowed on POST Requests
Use curl and $upstream_status to see whether a POST request hit a static fallback or reached your application. Then fix the API path, proxy mapping, or method.

The page loads, but clicking Submit returns 405 Method Not Allowed. In the browser’s Network panel, check the exact method and path that failed. It might be POST /contact, POST /api/contact, or an OPTIONS request the browser sent first. Typing the address in a browser only tests GET.
A 405 means the server recognizes the method and the resource does not accept it. HTTP requires an origin to include an Allow header listing the supported methods. In the Nginx static-file case below, the error came back without that header, so the access log was needed to locate the response. HTTP 405 specification · Nginx static module source
Use a hostname you manage in a test environment. Change the example data and content type to match your API. Keep the first response visible so you can read any Location header before following a redirect. With curl, --data sends a POST and -i includes the response headers.
curl -sS -i 'https://example.com/contact'
curl -sS -i --data 'name=example' 'https://example.com/contact'
curl -sS -i --data 'name=example' 'https://example.com/api/contact'
I ran these equivalent requests against a loopback Nginx 1.19.6 server. The front end used try_files to fall back to index.html. A small Python app handled /api/contact and used 201 to acknowledge the sample POST.
| Request | Response | Upstream status in the Nginx log |
|---|---|---|
| GET /contact | 200, static page | - |
| POST /contact | 405, Nginx error page | - |
| GET /api/contact | 405 with Allow: POST | 405 |
| POST /api/contact | 201, application acknowledgement | 201 |
The static fallback produced the first 405. The application produced the second. The fix depends on whether you need to change the proxy route or the application method.
Define a temporary log format in the http block. In the affected server block, enable it with access_log /var/log/nginx/method-check.log method_check;. Validate the file, reload, and match one test request to its log timestamp. Since $uri shows the URI while Nginx is processing the request, an internal redirect can change it to /index.html.
log_format method_check '$request_method $uri status=$status upstream=$upstream_status';
A line with status=405 upstream=- means this Nginx instance recorded no upstream response. Use nginx -T to inspect the active virtual host, the matching location, any try_files fallback, rewrites, and explicit return 405 rules. An absent log entry calls for checking whether the request reached this proxy. With status=405 upstream=405, use the time of the request to find the matching application log and check the route’s methods. A configured error page can hide the original response body, so compare the upstream status even if the page says Nginx. Nginx upstream log variables · Nginx command-line parameters
If your application exposes POST /api/contact, set the form’s action or the front-end fetch URL to /api/contact. With the app listening on 127.0.0.1:8080, these two locations belong in the existing virtual host. Keep the authentication and forwarding settings already required by your app.
location = /api/contact {
proxy_pass http://127.0.0.1:8080;
}
location / {
try_files $uri /index.html;
}
Here proxy_pass has no URI, so the sample path reaches the app as /api/contact. When you add a URI to proxy_pass, Nginx can replace the part matched by the location. Check the actual upstream path, especially for a prefix like /api/. Run sudo nginx -t before reloading. Test the public page and the test submission, then verify the app recorded the expected result. proxy_pass URI behavior · try_files fallback
A cross-origin JSON request can trigger a preflight OPTIONS request. A 405 on that request may stop the browser before it sends the POST. Identify the service that owns the CORS policy for the route, check the allowed origin, methods, and request headers, then run the browser test again. A successful curl POST confirms the API can handle that request without testing the browser’s preflight. Fetch preflight rules
To trace other mismatches between the proxy and the app, see how to read Nginx 499 logs or how to diagnose a 414 on a long URL.
Next step: compare the actual plans
Filter the listed plans by budget, specifications and region, or start with a buying guide.