Skip to content

WebDav Based On Caddy

Introduction

This article introducing a method on servering webdav service with CaddyServer.

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-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
    

  • On RHEL/CentOS/RockyLinux

    dnf install 'dnf-command(copr)'
    dnf copr enable @caddy/caddy
    dnf install caddy
    

2. Add Modules for Caddy

  • Add Packages Online

    sudo caddy add-package XXX
    
    XXX 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 caddy file with downloaded:

    sudo mv caddy /usr/bin
    sudo chmod +x /usr/bin/caddy
    sudo restorecon /usr/bin/caddy
    sudo chown root:root /usr/bin/caddy
    

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/caddy Adding paramter to service file /usr/lib/systemd/system/caddy.service under [service] lable:

  • Reload systemd

    sudo systemctl daemon-reload

4. Make caddy has authority to access files

  • Change the owner of /path/to/data with caddy

    sudo chwon caddy /path/to/data -R

  • Add caddy to the group of the files' owner

    sudo usermod -a -G $GROUP

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
    }
    

REF

[1]. https://caddyserver.com/docs/install

[2]. https://www.redhat.com/sysadmin/mastering-systemd

[3]. https://github.com/abiosoft/caddy-webdav