WebDav Based On Caddy
Introduction
Section titled “Introduction”This article introducing a method on servering webdav service with CaddyServer.
1. Install CaddyServer
Section titled “1. Install CaddyServer”The easiest way to install caddy is using package manager.
-
On Debian/Ubuntu
sudo apt install -y debian-keyring debian-archive-keyring apt-transport-httpscurl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' \| sudo gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpgcurl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' \| sudo tee /etc/apt/sources.list.d/caddy-stable.listsudo apt updatesudo apt install caddy -
On RHEL/CentOS/RockyLinux
dnf install 'dnf-command(copr)'dnf copr enable @caddy/caddydnf install caddy
2. Add Modules for Caddy
Section titled “2. Add Modules for Caddy”-
Add Packages Online
sudo caddy add-package XXXXXX is the package name, which always start with
github.com/xxxxxx.It’s easy to find packages name from Download Page.
Examples:
install webdav module:
sudo caddy add-package github.com/mholt/caddy-webdav -
Add Packages Manually
Select and Download CaddyServer with modules from Download Page.
Replace executable
caddyfile with downloaded:sudo mv caddy /usr/binsudo chmod +x /usr/bin/caddysudo restorecon /usr/bin/caddysudo chown root:root /usr/bin/caddy
3. Modify CaddyServer’s service file
Section titled “3. Modify CaddyServer’s service file”Due to the configuration in default systemd file, the parameter ProtectSystem=full, caddy lose the permission on writing /usr, /boot and /etc.(Reference-2 for details).
-
Add ReadWrite permission to caddy web folder
/usr/share/caddyAdding paramter to service file/usr/lib/systemd/system/caddy.serviceunder[service]lable: -
Reload systemd
sudo systemctl daemon-reload
4. Make caddy has authority to access files
Section titled “4. Make caddy has authority to access files”-
Change the owner of
/path/to/datawithcaddysudo chwon caddy /path/to/data -R -
Add
caddyto the group of the files’ ownersudo usermod -a -G $GROUP
5. Config Caddyfile
Section titled “5. Config Caddyfile”-
webdav Module Configure introduction is available: caddy-webdav
{basicauth {username password_generate_by_openssl}root * /path/to/data/route {rewrite /webdav /webdav/webdav /webdav/* {prefix /webdav}}file_server browse} -
global config set webdav before file_server:
{order webdav before file_server}
[1]. https://caddyserver.com/docs/install
[2]. https://www.redhat.com/sysadmin/mastering-systemd