I've been using caddy as a web server and reverse proxy for a few years and am generally happy with it, though the process of installing it is never simple. As I write this, I am moving my web server/rprox to a new box, so I'm going to document it for the next time I do it. I'll probably be using caddy2 at that point, and none of this will be relevant.

Stuff Needed

I keep a ~/caddyMess directory with:

This is enough to get started. I don't move certs or logs.

Go

  1. Put the binary in /usr/local/bin/caddy
    sudo cp caddy /usr/local/bin/caddy
  2. Let the binary bind privileged ports
    sudo setcap 'cap_net_bind_service=+ep' /usr/local/bin/caddy
  3. Set up the user, group, and directories
    sudo groupadd -g 33 www-data
    sudo useradd \
      -g www-data --no-user-group \
      --home-dir /var/www --no-create-home \
      --shell /usr/sbin/nologin \
      --system --uid 33 www-data
    
    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
  4. Install the service file
    sudo cp caddy.service /etc/systemd/system/
    sudo chown root:root /etc/systemd/system/caddy.service
    sudo chmod 644 /etc/systemd/system/caddy.service
    sudo systemctl daemon-reload
  5. Install the caddyfile (edit as needed obvs)
    sudo cp Caddyfile /etc/caddy/Caddyfile
  6. Start and enable the service
    sudo systemctl --now enable caddy ; sudo systemctl status caddy