基于Caddy的WebDav## 介绍本文介绍一种使用CaddyServer来提供webdav服务的方法。¶
1.安装CaddyServer安装 caddy 最简单的方法是使用包管理器。¶
-
在 Debian/Ubuntu 上
sudo apt install -y debian-keyring debian-archive-keyring apt-transport-https curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' \ | sudo gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' \ | sudo tee /etc/apt/sources.list.d/caddy-stable.list sudo apt update sudo apt install caddy -
在 RHEL/CentOS/RockyLinux 上
dnf install 'dnf-command(copr)' dnf copr enable @caddy/caddy dnf install caddy
2.添加Caddy模块- 在线添加套餐 ```¶
sudo caddy add-package XXX
```
XXX 是包名称,始终以github.com/xxxxxx开头。
从[下载页面][下载页面]很容易找到包名称。
示例: > 安装 webdav 模块: > >
sudo caddy add-package github.com/mholt/caddy-webdav
- 手动添加包
从[下载页面][DownloadPage]选择并下载带有模块的CaddyServer。
将可执行的
caddy文件替换为下载的:sudo mv caddy /usr/bin sudo chmod +x /usr/bin/caddy sudo restorecon /usr/bin/caddy sudo chown root:root /usr/bin/caddy
3.修改CaddyServer的服务文件由于默认systemd文件中的配置,参数ProtectSystem=full,caddy失去了写入/usr,/boot和/etc的权限。(详见[参考2])。¶
- 添加对 caddy web 文件夹
/usr/share/caddy的读写权限将参数添加到[service]标签下的服务文件/usr/lib/systemd/system/caddy.service中: - 重新加载系统
sudo systemctl daemon-reload
4.使caddy有访问文件的权限- 将/path/to/data的所有者更改为caddy¶
sudo chwon caddy /path/to/data -R
- 将caddy添加到文件所有者组
sudo usermod -a -G $GROUP
5.配置Caddyfile¶
-
webdav模块配置介绍可参考:[caddy-webdav][webdav] ``` { basicauth { username password_generate_by_openssl }
root * /path/to/data/ route { rewrite /webdav /webdav/ webdav /webdav/* { prefix /webdav } } file_server browse} ```
-
全局配置在 file_server 之前设置 webdav:
{ order webdav before file_server }
参考文献[1]. https://caddyserver.com/docs/install¶
[2]. https://www.redhat.com/sysadmin/mastering-systemd
[3]. https://github.com/abiosoft/caddy-webdav
[4]. 在 RHEL 上使用 Caddy 进行反向代理 [参考2]:https://www.redhat.com/sysadmin/mastering-systemd[下载页面]:https://caddyserver.com/download[webdav]:https://github.com/WingLim/caddy-webdav