WebDAV扩展

在以下文档中,假设 Seafile 的安装目录为 /opt/seafile
配置 WebDAV扩展
配置文件路径为:
  • 如果通过二进制包部署,则路径为 /opt/seafile/conf/seafdav.conf
  • 如果是常规安装,则路径为 /opt/seafile-data/seafile/conf/seafdav.conf
如果该文件不存在,可以自行创建。
示例配置:
            
                
                
[WEBDAV]

# 默认值为 false。修改为 true 以启用 SeafDAV 服务器。
enabled = true

port = 8080
debug = true

# 如果 SeafDAV 部署在 nginx/apache 之后,需要修改 "share_name"
share_name = /seafdav

# SeafDAV 使用 Gunicorn 作为 Web 服务器。
# 此选项对应 Gunicorn 'workers' 配置:https://docs.gunicorn.org/en/stable/settings.html?#workers
# 默认设置为 5 个进程。
workers = 5

# 此选项对应 Gunicorn 'timeout' 配置:https://docs.gunicorn.org/en/stable/settings.html?#timeout
# 默认设置为 1200 秒,用于支持大文件上传。
timeout = 1200
每次修改配置后,都需要 重启 Seafile 服务器 以使配置生效:
docker 部署:
            
                
                
docker compose restart
二进制包部署:
            
                
                
cd /opt/seafile/seafile-server-latest/
./seafile.sh restart
你的 WebDAV 客户端可以通过以下地址访问 Seafile WebDAV 服务器:
  • 普通部署: http{s}://example.com/seafdav/
  • 如果通过二进制包部署: http{s}://example.com:8080/seafdav/
在专业版 7.1.8 和社区版 7.1.5 中,增加了一个选项,可以在 SeafDAV 返回的库名后附加库 ID:
            
                
                
show_repo_id=true
代理配置(仅适用于二进制包部署)
提示: 如果使用 Docker 部署,WebDAV 服务器已经通过 /seafdav/* 做了代理,可以跳过此步骤。
Nginx 配置示例:
            
                
                
.....

location /seafdav {
     rewrite ^/seafdav$ /seafdav/ permanent;
}

location /seafdav/ {
     proxy_pass http://127.0.0.1:8080/seafdav/;
     proxy_set_header Host $host;
     proxy_set_header X-Real-IP $remote_addr;
     proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
     proxy_set_header X-Forwarded-Host $server_name;
     proxy_set_header X-Forwarded-Proto $scheme;
     proxy_read_timeout 1200s;
     client_max_body_size 0;

     access_log /var/log/nginx/seafdav.access.log seafileformat;
     error_log /var/log/nginx/seafdav.error.log;
}

location /:dir_browser {
     proxy_pass http://127.0.0.1:8080/:dir_browser;
}
客户端注意事项
请注意,当你将 Seafile WebDAV 服务器映射为本地文件系统(或网络驱动器)时,存在一些已知的性能限制:
1. 一次上传大量文件通常比同步客户端慢得多,因为每个文件都需要单独提交。
2. 访问 WebDAV 服务器有时会比较慢,这是因为本地文件系统驱动会发送很多不必要的请求以获取文件属性。
因此,WebDAV 更适合 偶尔访问文件 的场景。如果需要更好的性能,建议使用同步客户端。
Windows:
Windows 资源管理器支持 HTTPS 连接,但要求服务器上有有效的证书。 通常建议使用 Windows 资源管理器将 WebDAV 服务器映射为网络驱动器。 如果使用自签名证书,需要将证书的 CA 添加到 Windows 系统的 CA 存储中。
Linux:
在 Linux 上可选择的方式更多。
可以使用文件管理器(如 Nautilus)连接 WebDAV 服务器,也可以通过命令行使用 davfs2。
使用 davfs2 的示例:
            
                
                
sudo apt-get install davfs2
sudo mount -t davfs -o uid=<username> https://example.com/seafdav /media/seafdav/
其中 -o 选项设置挂载目录的所有者,使非 root 用户也可以写入。
建议禁用 davfs2 的 LOCK 操作,需要编辑 /etc/davfs2/davfs2.conf
            
                
                
use_locks 0
Mac OS X:
Finder 对 WebDAV 的支持不太稳定且速度较慢,因此建议使用专业 WebDAV 客户端软件,如 Cyberduck。
常见问题:
1.客户端无法连接到 SeafDAV 服务器
默认情况下,SeafDAV 是禁用的。 请检查 seafdav.conf 中是否设置了 enabled = true 。如果没有,请修改并重启 Seafile 服务器。
2.客户端收到 “Error: 404 Not Found”
如果 SeafDAV 部署在 Nginx 或 Apache 后面,请确保 share_name 已按照示例配置修改。 修改后重启 Seafile 服务器再尝试连接。
3.无法重命名或移动文件/文件夹
首先检查 seafdav.log ,看看是否有如下日志:
            
                
                
"MOVE ... -> 502 Bad Gateway
如果启用了调试模式,还会有类似如下日志:
            
                
                
09:47:06.533 - DEBUG : Raising DAVError 502 Bad Gateway: Source and destination must have the same scheme.
09:47:06.533 - DEBUG : Caught (502, "Source and destination must have the same scheme.\nIf you are running behind a reverse proxy, you may have to rewrite the 'Destination' header.\n(See https://github.com/mar10/wsgidav/issues/183)")
此问题通常出现在配置了 HTTPS,但请求被转发后,Seafile 接收到的 HTTP_X_FORWARDED_PROTO 不是 HTTPS。
解决方法:手动修改 HTTP_X_FORWARDED_PROTO 的值。例如,在 Nginx 中,将:
            
                
                
proxy_set_header X-Forwarded-Proto $scheme;
改为:
            
                
                
proxy_set_header X-Forwarded-Proto https;
4. Windows 资源管理器报告 “file size exceeds the limit allowed and cannot be saved”
当将 WebDAV 映射为网络驱动器,并尝试从网络驱动器复制大约 50MB 以上的文件到本地文件夹时,会出现此问题。
原因是 Windows 资源管理器限制了从 WebDAV 服务器下载的文件大小。 解决方法:在客户端机器上修改注册表,将下载文件大小限制调大。
注册表路径:
            
                
                
HKEY_LOCAL_MACHINE -> SYSTEM -> CurrentControlSet -> Services -> WebClient -> Parameters
键名: FileSizeLimitInBytes