NGINX index directive with PUT and DELETE requests

I just spent ages trying to figure this out, so I hope this post saves someone else some time.

I have a script named index.php that I want to send requests to by just referring to the directory it’s in, relying on the server to send the requests to the right place. I do that to keep the URLs simpler, and to make it easier to swap out the script for something else later without changing everything that refers to it.

That works great with regular GET and even POST requests, but for PUT and DELETE I was getting “405 Method Not Allowed” errors. After more digging around and false starts that I’d like to admit, I noticed that sending requests directly to index.php worked fine. It turns out that NGINX’s index directive does not allow PUT or DELETE.

That doesn’t seem to be officially documented anywhere, and the only workaround I’ve found is to either rewrite all URLs ending in “/”, which seems like overkill, or point the script sending those particular requests directly to the file instead of the directory.