DAV-Ext#

该模块扩展了 WebDAV 支持,增加了 PROPFIND、OPTIONS、LOCK 和 UNLOCK 方法。

标准模块 DAV 提供了 WebDAV 的部分实现,仅支持 GET、HEAD、PUT、DELETE、MKCOL、COPY 和 MOVE 方法。 要实现完整的 WebDAV 支持,您需要启用标准模块 http_dav_module,以及此模块以支持缺失的方法。

加载模块#

main{} 的上下文中加载模块:

load_module modules/ngx_http_dav_ext_module.so;

配置示例#

dav_ext_lock_zone zone=lock_zone:10m;
server {
    listen 80 default_server;

    location / {
        root /usr/share/angie/html;

        dav_methods PUT DELETE MKCOL COPY MOVE;
        dav_ext_methods PROPFIND OPTIONS LOCK UNLOCK;
        dav_ext_lock zone=lock_zone;
    }
}

请求执行示例#

将文件上传到服务器:

$ curl -i -X PUT -d @testf1.txt http://127.0.0.1/testf1.txt
HTTP/1.1 201 Created
Server: Angie/1.8.3
Date: Thu, 06 Mar 2025 12:08:40 GMT
Content-Length: 0
Location: http://127.0.0.1/testf1.txt
Connection: keep-alive

覆盖同一文件:

$ curl -i -X PUT -d @testf1.txt http://127.0.0.1/testf1.txt
HTTP/1.1 204 No Content
Server: Angie/1.8.3
Date: Thu, 06 Mar 2025 12:09:37 GMT
Connection: keep-alive

锁定文件以防止被覆盖:

$ curl -i -X LOCK http://127.0.0.1/testf1.txt
HTTP/1.1 200 OK
Server: Angie/1.8.3
Date: Thu, 06 Mar 2025 12:10:33 GMT
Content-Type: text/xml; charset=utf-8
Content-Length: 392
Connection: keep-alive
Lock-Token: <urn:7502d56f>

尝试覆盖文件:

$ curl -i -X PUT -d @testf1.txt http://127.0.0.1/testf1.txt
HTTP/1.1 423
Server: Angie/1.8.3
Date: Thu, 06 Mar 2025 12:11:30 GMT
Content-Length: 0
Connection: keep-alive

文件已被锁定。解锁文件:

$ curl -i -X UNLOCK -H 'Lock-Token: <urn:7502d56f>' http://127.0.0.1/testf1.txt
HTTP/1.1 204 No Content
Server: Angie/1.8.3
Date: Thu, 06 Mar 2025 12:43:21 GMT
Connection: keep-alive

覆盖文件:

$ curl -i -X PUT -d @testf1.txt http://127.0.0.1/testf1.txt
HTTP/1.1 204 No Content
Server: Angie/1.8.3
Date: Thu, 06 Mar 2025 12:43:38 GMT
Connection: keep-alive

文件已成功解锁并被覆盖。

附加信息#

详细文档和源代码可在以下地址获取: arut/nginx-dav-ext-module