WebDAV扩展

在以下文档中,假设 Seafile 的安装目录为 /opt/seafile。
修改 .env
在 .env 文件中启用 WebDAV 扩展。
# 默认值为 false。修改为 true 以启用 SeafDAV 服务器。
ENABLE_SEAFDAV = true
# SeafDAV 使用 Gunicorn 作为 Web 服务器。
# 此选项对应 Gunicorn 的 workers 设置:https://docs.gunicorn.org/en/stable/settings.html?#workers
# 默认设置为 5 个进程。
SEAFDAV_WORKERS = 5
配置 WebDAV 扩展
配置文件路径为 /opt/seafile-data/seafile/conf/seafdav.conf。如果通过二进制包部署,则配置文件路径为 /opt/seafile/conf/seafdav.conf。如果该文件尚不存在,可以自行创建。
配置示例:
[WEBDAV]
port = 8080
debug = true
share_name = /seafdav
# 此选项对应 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
SeafDAV 的 Nginx 配置如下:
# ……(其他 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;
}
Apache
SeafDAV 的 Apache 配置如下:
# ……(其他 Apache 配置)
<Location /seafdav>
ProxyPass "http://127.0.0.1:8080/seafdav"
</Location>
客户端注意事项
首先需要注意:将 Seafile WebDAV 服务器映射为本地文件系统(或网络驱动器)时,存在一些已知的性能限制:
  • 一次上传大量文件通常比使用同步客户端慢得多,因为每个文件都需要单独提交。
  • 访问 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 的支持不够稳定,而且速度较慢。因此,建议使用 Cyberduck 等专用 WebDAV 客户端软件。
常见问题
1. 客户端无法连接到 SeafDAV 服务器
默认情况下,SeafDAV 处于禁用状态。官方英文文档此处要求检查 seafdav.conf 中是否设置了 enabled = true;如果没有,则修改配置并重启 Seafile 服务器。
译注: 官方页面的这条常见问题与前文的配置说明不一致。按照本页「修改 .env」一节,Seafile 14.0 应在 .env 文件中设置 ENABLE_SEAFDAV = true 来启用 WebDAV。这里保留原文信息,并指出该不一致之处。
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.
If you are running behind a reverse proxy, you may have to rewrite the 'Destination' header.
(See https://github.com/mar10/wsgidav/issues/183)
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 映射为网络驱动器后,如果尝试从网络驱动器向本地文件夹复制大约 50 MB 以上的文件,可能会出现此问题。
原因是 Windows 资源管理器对从 WebDAV 服务器下载的文件大小设置了限制。要提高此限制,需要在客户端计算机上修改注册表。
注册表路径为:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\WebClient\Parameters
该路径下的注册表项名称为:FileSizeLimitInBytes。