'NGINX : DELETE method not allowed

I am using Nginx to serve static pages but to pass requests to an API, which I would like to handle GET, and DELETE requests.

GET work fine, but DELETE request is rejected with "405: Method Not Allowed"

server {
    listen 80;
    server_name test.com;
    root /var/test/cache/;
    index index.php;

    add_header 'Access-Control-Allow-Methods' 'GET, DELETE';
    add_header 'Access-Control-Allow-Headers' 'Content-Type, Origin';
    add_header 'Access-Control-Allow-Origin' '*';


    location ~* /questions {
      ...
      
      try_files $url /index.php;
    }

}     

Any suggestion will be helpful, thanks.



Solution 1:[1]

Solution :

fix an issue on fastcgi_params file, and improve the location rule entry :

server {
    listen 80;
    server_name test.com;
    root /var/test/cache/;
    index index.php;

    location ~* /questions {
      
      set_by_lua_block $url_format {
        request_type = ngx.var.request_method
        
        if request_type == 'DELETE' then
           ...
           return url_format;
        end
        
        ...
      }
      
      try_files $url_format /index.php;
    }

} 

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 algo tourist