DELETE requests return 405 (Method not Allowed)

Hello, world.

I am experiencing an issue with CloudFlare regarding an API I run behind it.
For some reason, DELETE requests always return HTTP 405 - Method not Allowed. This only happens when I access my API from CloudFlare; accessing it directly returns the proper response, which seems to indicate that CloudFlare is to blame here. This is not the API returning the error.

I checked the firewall section and didn’t see the requests being blocked there. I also went over my page rules, and I do not have any rule that may cause this.

What can I do about this? Am I right to think this is a problem with CloudFlare?
Your assistance is appreciated. Thank you.

I thought I remembered that Cloudflare wouldnt proxy DELETE requests, however I couldnt find the thread I was looking for. And a quick test did seem to work so I would expect DELETE to work.

Would you have a demo link?

@sandro

Indeed. I set up a test endpoint here: https://api.crescent.gg/v2/methodtest/
It simply responds with the request type:

<?php
    echo "Hello, yes. " . $_SERVER['REQUEST_METHOD'] . " received.";
?>

You can try and see how GET and POST work, but all others end up as 405, including DELETE.

I just tried the same script too a site behind Cloudflare and actually got the correct response back. So it is either something about your security settings on Cloudflare or the response comes from your server.

Would you feel comfortable sharing your server IP address here?

The error page says “nginx/1.14.0 (Ubuntu)”. That would rather hint at a response from your server than Cloudflare.

1 Like

Whew! What do you know - it really was my web server after all.

I was using nginx index (https://nginx.org/en/docs/http/ngx_http_index_module.html) to remove the index.php part from URLs. Turns out, however, that it doesn’t quite work with anything other than GET and POST.
I switched to using nginx rewrite (https://nginx.org/en/docs/http/ngx_http_rewrite_module.html) and it works great.

In case anyone stumbles into this thread in the future in search of a similar solution:
In your nginx site config, remove index XXX, and instead add this:

    location / {
            rewrite ^(.*)/(.*)$ $1/index.php$2 last;
    }

Thank you for your help, @sandro!

This topic was automatically closed after 14 days. New replies are no longer allowed.