Caddy
Caddy is a modern web server that handles HTTPS provisioning and certificate renewals automatically.
Generate a Caddyfile
docmd deploy --caddy
This generates a Caddyfile personalised to your project:
- Site address is set to the hostname from your
urlconfig — Caddy will automatically provision an SSL certificate for it. Falls back to:80if no URL is configured. - Root directory uses your configured
outdirectory (not hardcoded) - SPA fallback is only included when
layout.spaistruein your config
What Gets Generated
docs.example.com {
root * ./site
file_server
# SPA Routing Fallback (only when layout.spa is true)
try_files {path} {path}/ /index.html
# Security Headers
header {
X-Content-Type-Options "nosniff"
X-Frame-Options "SAMEORIGIN"
-Server
}
# Custom 404
handle_errors {
rewrite * /404.html
file_server
}
# Cache Static Assets (6 months)
@static {
file
path *.ico *.css *.js *.gif *.jpg *.jpeg *.png *.webp *.avif *.svg *.woff *.woff2 *.eot *.ttf *.otf
}
header @static Cache-Control "public, max-age=15552000, immutable"
}
When you use a real domain as the site address (e.g., docs.example.com instead of :80), Caddy automatically provisions a free SSL certificate via Let’s Encrypt — zero HTTPS configuration needed.
Deployment Steps
- Build your site:
docmd build - Transfer your output folder and the generated
Caddyfileto your server. - Run
caddy startorcaddy runin the directory containing your Caddyfile.
Re-Generating
Changed your site URL or output directory? Run docmd deploy --caddy again — the Caddyfile is regenerated to match your current docmd.config.js.