1. Prepare a dedicated document root
sudo mkdir -p /var/www/example-site
sudo chown -R root:root /var/www/example-site
sudo find /var/www/example-site -type d -exec chmod 755 {} \;
sudo find /var/www/example-site -type f -exec chmod 644 {} \;Static files should normally be readable by the web server but not writable by it. If a deployment process needs write access, grant it only to the deployment directory or account.
2. Add a minimal page
printf '%s\n' 'Example It works
' | sudo tee /var/www/example-site/index.html
3. Understand a Caddy site block
A minimal Caddyfile site definition looks like this:
example.com {
root * /var/www/example-site
encode zstd gzip
file_server
}Caddy can obtain and renew certificates automatically when DNS, public reachability and ports are correctly configured. This example is a reference only; do not replace an existing production Caddyfile without reviewing all site blocks and reverse proxies.
4. Validate before applying
sudo caddy validate --config /etc/caddy/Caddyfile sudo systemctl status caddy --no-pager
Use the configuration path actually used by your service. A successful validation checks configuration parsing, not end-to-end application health.
5. Test the response
curl -I https://example.com/ curl -I https://example.com/assets/site.css curl -sS https://example.com/ | head
Check status code, content type and the actual response body. A page returning HTTP 200 can still contain broken asset paths or JavaScript errors.
6. Troubleshoot common problems
- 403: inspect file and parent-directory permissions.
- 404: confirm the configured root and requested path.
- TLS issuance failure: verify DNS, public reachability, port access and logs.
- Old content: inspect cache headers and use a hard refresh.
- 502: for reverse proxies, check upstream address, port and health.
7. Safe deployment checklist
- Back up the current site and config.
- Stage and inspect new files before copying.
- Keep ownership and permissions intentional.
- Validate configuration before reload.
- Test every page and asset over HTTPS.
- Keep a tested rollback copy.
References & further reading
Commands are examples for a representative Ubuntu/Linux environment. Review paths, versions, access requirements and maintenance impact before applying them to production systems.