Nginx repair of WebDAV functionality

If you want to use WebDAV for file sharing, in particular, want to use the operating system built-in features to mount the file system, then worry, then still with Apache it.

Below describes how to use Nginx to achieve this goal. Windows built-in client is a Microsoft-WebDAV-MiniRedir, macOS is WebDAVFS Darwin, Linux is gvfs.

You first need to nginx-DAV-EXT-Module , otherwise any WebDAV client can not work, because they do not support the PROPFIND command can not be listed directory. Windows / macOS write files need LOCK command, Linux is not required.

According to the document after configured, mount the network disk, OK, and then found it impossible to create a new folder and rename folders ...... no one operating system can survive ......

Here are two ways:

Modify the source code to compile

Just delete the code on the line, you do not need to write any new code, which leads you are embarrassed to mention to the official BUG-- can not not my fault, is Windows / macOS / Linux's fault, they do not outlaw the cards.

ngx_http_dav_module.c

Line 504, it is determined MKCOL uri instruction must end with "/", and finally passed to the operating system layer is removed when "/" is actually a function of the operating system compatible mkdir "a" and "A /" formats.

WIndows / macOS / Linux can not create a cause of the mount folder.

    // if (r->uri.data[r->uri.len - 1] != '/') {
    //     ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
    //                   "MKCOL can create a collection only");
    //     return NGX_HTTP_CONFLICT;
    // }

    p = ngx_http_map_uri_to_path(r, &path, &root, 0);
    if (p == NULL) {
        return NGX_HTTP_INTERNAL_SERVER_ERROR;
    }

    // *(p - 1) = '\0';
    // r->uri.len--;

 Line 636, determines the end of the MOVE instruction and Destination, uri "/" must match, in fact, operating systems compatible with the same rename function "a" and "A /", the file can not be changed folder.

One of the reasons macOS not rename the folder --uri ends with /, Destination no / end with.

 // if ((r->uri.data[r->uri.len - 1] == '/' && *(last - 1) != '/')
    //     || (r->uri.data[r->uri.len - 1] != '/' && *(last - 1) == '/'))
    // {
    //     ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
    //                   "both URI \"%V\" and \"Destination\" URI \"%V\" "
    //                   "should be either collections or non-collections",
    //                   &r->uri, &dest->value);
    //     return NGX_HTTP_CONFLICT;
    // }

 764 line, if MOVE is the type of the folder, then, uri must end with "/", ibid, the operating system rename function compatible.

Windows / Linux can not rename the folder reason, macOS second reason can not rename the folder.

        // if (r->uri.data[r->uri.len - 1] != '/') {
        //     ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
        //                   "\"%V\" is collection", &r->uri);
        //     return NGX_HTTP_BAD_REQUEST;
        // }

After he recompile, Windows / macOS / Linux mount network-hours basically available.

But on Windows, you can create a new file, upload the file is still unavailable. After Windows file copy time stubbornly put new files into the original file and the same, because of the lack PROPPATCH command, this operation can not be completed on strike, macOS / Linux do not do this operation. Windows is actually very friendly to this habit by the time the file to determine whether the updated tools make the like, often misjudged. WebDAV with Apache to do when I sometimes found when uploading new files can not trigger the update script, because the time to upload a file behind the server time.

Someone offers a fake PROPPATCH achieve, as PROPFIND is the direct instruction processing. In my opinion even better than the realization of the right, people stubborn behavior of Windows to avoid errors caused by irritable.

Profiles

If you do not want to compile it yourself, using the configuration file can be resolved.

MKCOL not end with a /

if ($request_method = MKCOL) { rewrite ^(.*[^/])$ $1/ break; }

Under Windows MOVE folder to / does not end with

if (-d $request_filename) {
    rewrite ^(.*[^/])$ $1/;
    set $md /;
}

Rename the folder Destination does not end with a /, it is necessary headers-more-nginx-module

set $x $http_destination$request_method;
if ($x ~ [^/]MOVE) {
    more_set_input_headers -r "Destination: ${http_destination}${md}";
}

PROPPATCH no instruction processing PROPFIND.

proxy_method PROPFIND;
include proxy_params;
if ($request_method = PROPPATCH) {
    proxy_pass http://127.0.0.1;
}

 Kick call it a day.

Guess you like

Origin www.cnblogs.com/yunteng/p/12449604.html