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 at the beginning of the previous post.

2. Install Caddy WebDAV module

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

The easiest way, however, is to add it directly from Caddy using its 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 the Caddy config file to add WebDAV 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 the WebDAV module for the webdav.example.com domain and use /data/webdav as the root directory.

It also secures access to files using basic authentication. The hashed password for 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 the WebDAV protocol from anywhere.

Keywords: caddy webdav site hosting linux