情況
我已經設定了一個基於 NGINX 且啟用了 SSL 的 Webdav 伺服器。當我嘗試從 Windows 資源管理器連接到伺服器時,一切正常,直到我上傳檔案。 Windows 資源管理器說目標已經有一個名為“[文件名]”的文件,如果單擊代替,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.conf
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。我最終求助於使用 Apachedav
和dav_fs
模組。
答案2
嘗試從那裡使用配置http://netlab.dhis.org/wiki/ru:software:nginx:webdav 這對我來說是工作。