情况
我已经设置了一个基于 NGINX 的 Webdav 服务器,并启用了 SSL。当我尝试从 Windows 资源管理器连接到服务器时,一切正常,直到我上传文件。Windows 资源管理器说目标位置已有一个名为“[filename]”的文件,如果点击代替,Windows 提示无法读取源文件或磁盘。
失败后,我刷新了 Windows 资源管理器,发现 Webdav 服务器上创建了一个与 [文件名] 完全相同的新文件,大小为 0kb(无数据)。
我尝试连接 WinSCP 和 Cyberduck,一切正常,上传/下载没有问题。
小解决方法
我检查了我的 NGINX 配置,没有发现任何问题。这是我的 NGINX 配置。
nginx.conf
worker_processes auto;
error_log /var/log/nginx/error.log;
load_module /usr/lib/nginx/modules/ngx_http_dav_ext_module.so;
events {
worker_connections 1024;
}
http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 4096;
include /etc/nginx/mime.types;
default_type application/octet-stream;
include /etc/nginx/conf.d/*.conf;
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
root /usr/share/nginx/html;
location / {
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
}
webdav配置文件
server {
listen 6999 ssl http2;
server_name my.domain;
ssl_certificate /path/to/fullchain.pem;
ssl_certificate_key /path/to/privkey.pem;
ssl_session_timeout 5m;
ssl_protocols TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_ciphers "EECDH+CHACHA20:EECDH+CHACHA20-draft:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5";
ssl_session_cache builtin:1000 shared:SSL:10m;
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
client_header_timeout 120s;
client_body_timeout 120s;
client_max_body_size 100m;
location / {
# Windows Explorer Workaround
#if (-d $request_filename) { rewrite ^(.*[^/])$ $1/ break; }
#if ($request_method = MKCOL) { rewrite ^(.*[^/])$ $1/ break; }
root /path/to/webdav/folder;
dav_methods PUT DELETE MKCOL COPY MOVE;
dav_ext_methods PROPFIND OPTIONS LOCK UNLOCK;
dav_access user:rw group:rw all:rw;
client_max_body_size 0;
create_full_put_path on;
client_body_temp_path /srv/client-temp;
autoindex on;
auth_basic on;
auth_basic_user_file /etc/nginx/users.list;
allow all;
}
}
我谷歌了一下,找到了这个文章。但是这没有帮助。
另外,我尝试将我的 webdav 文件夹权限设置为 777,并将所有者更改为 nginx,但没有帮助。
我检查了 NGINX 访问日志并发现了这一点。
xxx.xxx.xxx.xxx - username [29/Sep/2019:15:20:06 +0800] "PUT /config HTTP/2.0" 201 0 "-" "Microsoft-WebDAV-MiniRedir/10.0.18362" "-"
xxx.xxx.xxx.xxx - username [29/Sep/2019:15:20:06 +0800] "LOCK /config HTTP/2.0" 405 157 "-" "Microsoft-WebDAV-MiniRedir/10.0.18362" "-"
xxx.xxx.xxx.xxx - username [29/Sep/2019:15:20:06 +0800] "PROPFIND /config HTTP/2.0" 207 463 "-" "Microsoft-WebDAV-MiniRedir/10.0.18362" "-"
xxx.xxx.xxx.xxx - username [29/Sep/2019:15:20:07 +0800] "PROPFIND /config HTTP/2.0" 207 463 "-" "Microsoft-WebDAV-MiniRedir/10.0.18362" "-"
xxx.xxx.xxx.xxx - username [29/Sep/2019:15:20:07 +0800] "PROPFIND /config HTTP/2.0" 207 463 "-" "Microsoft-WebDAV-MiniRedir/10.0.18362" "-"
xxx.xxx.xxx.xxx - username [29/Sep/2019:15:20:07 +0800] "PROPFIND /Thumbs.db HTTP/2.0" 404 153 "-" "Microsoft-WebDAV-MiniRedir/10.0.18362" "-"
xxx.xxx.xxx.xxx - username [29/Sep/2019:15:20:07 +0800] "PROPFIND /Documents/somefile HTTP/2.0" 207 511 "-" "Microsoft-WebDAV-MiniRedir/10.0.18362" "-"
xxx.xxx.xxx.xxx - username [29/Sep/2019:15:21:33 +0800] "PROPFIND /macOS%20Files HTTP/2.0" 207 448 "-" "Microsoft-WebDAV-MiniRedir/10.0.18362" "-"
xxx.xxx.xxx.xxx - username [29/Sep/2019:15:21:33 +0800] "PROPFIND /Documents/somefile HTTP/2.0" 207 511 "-" "Microsoft-WebDAV-MiniRedir/10.0.18362" "-"
xxx.xxx.xxx.xxx - username [29/Sep/2019:15:21:33 +0800] "PROPFIND /config HTTP/2.0" 207 463 "-" "Microsoft-WebDAV-MiniRedir/10.0.18362" "-"
xxx.xxx.xxx.xxx - username [29/Sep/2019:15:21:33 +0800] "PROPFIND /config%20(2) HTTP/2.0" 404 153 "-" "Microsoft-WebDAV-MiniRedir/10.0.18362" "-"
xxx.xxx.xxx.xxx - username [29/Sep/2019:15:21:33 +0800] "PROPFIND / HTTP/2.0" 207 424 "-" "Microsoft-WebDAV-MiniRedir/10.0.18362" "-"
xxx.xxx.xxx.xxx - username [29/Sep/2019:15:21:33 +0800] "LOCK /config HTTP/2.0" 405 157 "-" "Microsoft-WebDAV-MiniRedir/10.0.18362" "-"
xxx.xxx.xxx.xxx - username [29/Sep/2019:15:21:33 +0800] "PROPFIND /config HTTP/2.0" 207 463 "-" "Microsoft-WebDAV-MiniRedir/10.0.18362" "-"
xxx.xxx.xxx.xxx - username [29/Sep/2019:15:21:33 +0800] "LOCK /config HTTP/2.0" 405 157 "-" "Microsoft-WebDAV-MiniRedir/10.0.18362" "-"
xxx.xxx.xxx.xxx - username [29/Sep/2019:15:21:33 +0800] "PROPFIND /config HTTP/2.0" 207 463 "-" "Microsoft-WebDAV-MiniRedir/10.0.18362" "-"
xxx.xxx.xxx.xxx - username [29/Sep/2019:15:21:33 +0800] "LOCK /config HTTP/2.0" 405 157 "-" "Microsoft-WebDAV-MiniRedir/10.0.18362" "-"
xxx.xxx.xxx.xxx - username [29/Sep/2019:15:22:52 +0800] "PROPFIND /macOS%20Files HTTP/2.0" 207 448 "-" "Microsoft-WebDAV-MiniRedir/10.0.18362" "-"
xxx.xxx.xxx.xxx - username [29/Sep/2019:15:22:52 +0800] "PROPFIND /desktop.ini HTTP/2.0" 404 153 "-" "Microsoft-WebDAV-MiniRedir/10.0.18362" "-"
xxx.xxx.xxx.xxx - username [29/Sep/2019:15:22:52 +0800] "PROPFIND / HTTP/2.0" 207 424 "-" "Microsoft-WebDAV-MiniRedir/10.0.18362" "-"
xxx.xxx.xxx.xxx - username [29/Sep/2019:15:22:52 +0800] "PROPFIND / HTTP/2.0" 207 2231 "-" "Microsoft-WebDAV-MiniRedir/10.0.18362" "-"
xxx.xxx.xxx.xxx - username [29/Sep/2019:15:29:09 +0800] "PROPFIND /macOS%20Files HTTP/2.0" 207 448 "-" "Microsoft-WebDAV-MiniRedir/10.0.18362" "-"
xxx.xxx.xxx.xxx - username [29/Sep/2019:15:30:38 +0800] "PROPFIND /macOS%20Files HTTP/2.0" 207 448 "-" "Microsoft-WebDAV-MiniRedir/10.0.18362" "-"
NGINX 错误日志中没有日志输出。
非常感谢您的帮助!
答案1
这nginx webdav 模块仅支持 PUT、DELETE、MKCOL、COPY 和 MOVE。
这dav_ext 模块增加了对 PROPFIND、OPTIONS、LOCK 和 UNLOCK 的支持。
不幸的是,Windows 会尝试使用零大小文件的 PUT 创建文件,然后使用 PROPPATCH 复制内容。我没有成功使用 Nginx 在 Windows 上支持 WebDAV。我最终求助于使用带有dav
和dav_fs
模块的 Apache。
答案2
尝试使用那里的配置http://netlab.dhis.org/wiki/ru:software:nginx:webdav 这对我来说是工作。