0

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?

1 Answers1

0

Using alias is not recommended in your case (http://nginx.org/en/docs/http/ngx_http_core_module.html#alias). You could do something like this using a rewrite and root instead:

location /files/docs {
        rewrite ^/files/(docs.*)$ /$1 last;
}

location /docs {
        if (-d $request_filename) { rewrite ^(.*[^/])$ $1/ break; }
        root /srv/www;
        dav_methods DELETE;
}

This handles the folder structure first (removing the unnecessary part of the url/path) and then handels the trailing slash dilemma. Which works for me:

[22/Feb/2018:01:45:09 +0100] "DELETE /files/docs/testfile HTTP/1.1" 204 0 "-" "Microsoft-WebDAV-MiniRedir/10.0.16299"
[22/Feb/2018:01:45:09 +0100] "DELETE /files/docs/testfolder HTTP/1.1" 204 0 "-" "Microsoft-WebDAV-MiniRedir/10.0.16299"
cetteup
  • 166
  • 5