Setup Webdav using Caddy

2022-03-09 - setting up Caddy web server for Webdav

1. Prerequisites

In order to set up webdav you need to have Caddy installed. You can check how to do that in the beginning of the previous post.

2. Install Caddy Webdav module

Caddy Webdav requires installing a separate module. There are many ways to install module, from compiliing directly from source to installing a separate xcaddy tool to manage modules.

The easiest way however, is to add it directly from the caddy using his built-in add-package command.

sudo caddy add-package github.com/mholt/caddy-webdav
sudo systemctl restart caddy

3. Configuring Caddy

Now you need to edit Caddy config, file to add Wedbav support.

/etc/caddy/Caddyfile

# configure webdav module
{
    order webdav before file_server
}

# set up webdav for the webdav.example.com host
webdav.example.com {
    root * /data/webdav
    basicauth {
        user1 hashed-password
    }
    webdav
}

This setup will configure webdav module to wedbav.example.com domain and use /data/webdav as a root directory.

It also secures access to file using basic authentication. Hashed password for the user1 can be generated using Caddy:

caddy hash-password

Just paste the output of the above command into the config file.

You can now access your files using webdav prtocol from anywhere.

Keywords: caddy webdav site hosting linux