Skip to content
Beau Barker edited this page Jul 29, 2025 · 62 revisions

WebDAV, or Web-based Distributed Authoring and Versioning, is a set of extensions to the HTTP protocol that allows users to edit and manage files on a web server.

1. Credentials

WebDAV uses Basic Auth.

Hash a password:

bin/caddy caddy hash-password --plaintext 'demo'

Add it to the environment file:

.env

# WebDAV
WEBDAV_HASHED_PASS='(your hash)'

Caution

The .env file is for development only. Never store real secrets in plain text in production.

Add it to Caddy’s environment:

compose.yaml

caddy:
  environment:
    WEBDAV_HASHED_PASS: ${WEBDAV_HASHED_PASS:?}

2. Caddy

Add caddy-webdav

Build Caddy with the caddy-webdav module:

caddy/Dockerfile

FROM caddy:2-builder AS builder

RUN xcaddy build \
    --with github.com/ggicci/[email protected]

# Final lightweight image
FROM caddy:2

COPY --from=builder /usr/bin/caddy /usr/bin/caddy

# Copy our Caddyfile into the image
COPY Caddyfile /etc/caddy/Caddyfile

Then:

docker compose build caddy

Add a Volume

Add a volume and mount it in Caddy:

compose.yaml

services:
  caddy:
    volumes:
      - user_uploads:/uploads:rw

volumes:
  user_uploads:

Tip

You may want other services, such as Postgres, to also have access to the uploads.

Add a Route

Add a Caddy route for client apps to connect and manage files.

caddy/Caddyfile

handle /uploads/* {
  basicauth {
    demo {env.WEBDAV_HASHED_PASS}
  }
  route {
    root * /uploads
    webdav {
      prefix /uploads
    }
  }
}

Note

It might seem like we should use handle_path and remove prefix, but Caddy-webdav needs prefix to work correctly.

Note

You don't need file_browser because WebDAV itself implements GET, PUT, etc. but you may still want file_browser serve if you want regular browsers to be able to click around and download files.

Restart Caddy

docker compose restart caddy
Clone this wiki locally