Example for subdomain.domain.xyz
Log in to Cloudflare (cloudflare.com)
Go to Domains, Overview and click on domain.xyz
Click DNS > Records
Click + Add record
Type: CNAME
Name: subdomain
Target: domain.xyz
Proxy status: Proxied; this is the default
Expand Record Attributes and set a comment
Click Save
Log in to the web server.
Create a Caddyfile import:
sudo vi /etc/caddy/subdomain.caddy
subdomain.domain.xyz {
root * /srv/www
file_server
# Cloudflare SSL automation
tls {
dns cloudflare YOUR_CLOUDFLARE_API_TOKEN_HERE
}
# Strict isolation headers
header {
Cross-Origin-Opener-Policy "same-origin"
Cross-Origin-Embedder-Policy "require-corp"
}
}
Import to your main Caddyfile:
echo "import /etc/caddy/subdomain.caddy" | sudo tee -a /etc/caddy/Caddyfile
Restart Caddy
sudo systemctl restart caddy