This is a WIP, currently using ROOT and has some errors when starting regarding permissions, but my site worked as expected.
I use a seperate script for each site hosted
sudo setcap 'cap_net_bind_service=+ep' /usr/local/bin/caddy
sudo mkdir /etc/caddy
sudo chown -R root:root /etc/caddy
sudo mkdir /etc/ssl/caddy
sudo chown -R root:www-data /etc/ssl/caddy
sudo chmod 0770 /etc/ssl/caddy
cat << 'EOF' >/etc/caddy/domain/Caddyfile
chmod 644 /etc/caddy/domain/Caddyfile
chown root:root /etc/caddy/domain/Caddyfile
SystemD Service File:
cat << 'EOF' >/etc/systemd/system/domain.caddy.service
Description=Caddy HTTP/2 web server
; Do not allow the process to be restarted in a tight loop. If the
; process fails to start, something critical needs to be fixed.
; User and group the process will run as.
; Letsencrypt-issued certificates will be written to this directory.
; Always set "-root" to something safe in case it gets forgotten in the Caddyfile.
ExecStart=/usr/local/bin/caddy run -config=/etc/caddy/domain/Caddyfile --adapter caddyfile
ExecReload=/bin/kill -USR1 $MAINPID
; Use graceful shutdown with a reasonable timeout
; Limit the number of file descriptors; see `man systemd.exec` for more limit settings.
; Unmodified caddy is not expected to use more than that.
; Use private /tmp and /var/tmp, which are discarded after caddy stops.
; Use a minimal /dev (May bring additional security if switched to 'true', but it may not work on Raspberry Pi's or other devices, so it has been disabled in this dist.)
; Hide /home, /root, and /run/user. Nobody will steal your SSH-keys.
; Make /usr, /boot, /etc and possibly some more folders read-only.
; … except /etc/ssl/caddy, because we want Letsencrypt-certificates there.
; This merely retains r/w access rights, it does not add any new. Must still be writable on the host!
; The following additional security directives only work with systemd v229 or later.
; They further restrict privileges that can be gained by caddy. Uncomment if you like.
; Note that you may have to add capabilities required by any plugins in use.
chmod +x /etc/systemd/system/domain.caddy.service
systemctl enable /etc/systemd/system/domain.caddy.service
systemctl start /etc/systemd/system/domain.caddy.service
systemctl status /etc/systemd/system/domain.caddy.service