I have an Nginx server running over lightsail instance configured to handle various HTTP methods including GET, POST, and PUT. However, when I attempt to send a PUT request, I receive a 405 Method Not Allowed response.
Here’s the relevant part of my Nginx configuration file:
server {
listen 443 ssl default_server;
root /opt/bitnami/nginx/html/web;
server_name servername.com;
ssl_certificate /opt/bitnami/nginx/conf/servername.com.crt;
ssl_certificate_key /opt/bitnami/nginx/conf/servername.com.key;
location / {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS, PUT';
add_header 'Access-Control-Allow-Headers' 'DNT, X-CustomHeader, Keep-Alive, User-Agent, X-Requested-With, If-Modified-Since, Cache-Control, Content-Type, cache-control, expires, pragma';
add_header 'Access-Control-Max-Age' 86400;
if ($request_method = OPTIONS) {
return 204;
}
try_files $uri $uri/ /index.php?q=$uri&$args;
}
if (!-e $request_filename) {
rewrite ^/(.+)$ /index.php?q=$1 last;
}
include "/opt/bitnami/nginx/conf/bitnami/*.conf";
}
When I send a PUT request to my WooCommerce server, I get the following response:
// request
curl --location --request PUT 'https://servername.com/wp/?rest_route=%2Fsimple-jwt-login%2Fv1%2Fuser%2Freset_password&email=mail@mail.com&code=securecode&new_password=123456'
//response
<html>
<head><title>405 Not Allowed</title></head>
<body>
<center><h1>405 Not Allowed</h1></center>
<hr><center>nginx</center>
</body>
</html>
I'v confimrd that:
I’ve reviewed the Nginx configuration and confirmed that the method PUT should be allowed.
I’ve checked the backend server to ensure it is configured to handle PUT requests.
I’ve restarted Nginx after making changes to the configuration.
What might be causing the 405 Method Not Allowed error for PUT requests, and how can I resolve it? Thank you for your help!