I have a website where a particular section uses WebDAV methods (in particular, HTTP delete) to remove files. Configuring this is fairly easy:
location /files/docs {
auth_basic Restricted;
auth_basic_user_file /etc/nginx/htpasswd;
dav_methods DELETE;
}
This works well enough. However, some of my users use a non-compliant WebDAV client, which deletes directories by sending a DELETE /files/docs/some/folder
, instead of a DELETE /files/docs/some/folder/
according to the spec. (Notice the trailing /
). Leaving out the trailing /
results in a "409 Conflict" response from the server. Thus, I have to rewrite such directory requests to add the trailing /
.
This article deals with the issue, but the proposed solution doesn't work. My new rules are the following:
location /files/docs {
if (-d $request_filename) {
rewrite ^(.*[^/])$ $1/ break;
}
alias /srv/www/docs;
auth_basic Restricted;
auth_basic_user_file /etc/nginx/htpasswd;
dav_methods DELETE;
}
However, whenever a DELETE request is made, it errors out with:
*1 "alias" cannot be used in location "/files/docs" where URI was rewritten, client: (client IP), server: (server IP), request: "DELETE /files/docs/some/folder HTTP/2.0", host: (server IP)", referrer: "(referer)"
How do I work around this issue?