Caddy

HTTPS with Caddy, automatic or by hand.

Caddy serves HTTPS and gets the certificate from Let's Encrypt. It is the default proxy of the installer.

How the app is split

Zerodot has two apps behind one address:

  • The API app serves these paths: /api/v1/*, /api/auth/*, /api/p/*, /hooks/*, /hooks-test/*, /resume/*, /mcp, /mcp/* and /oauth2/*.
  • The web app serves all other paths.

In Docker mode, a Caddy container in the install does this split. The proxy on the server sends all traffic to one port.

In native mode, the proxy on the server does the split. It sends the API paths to the API port and the rest to the web port.

The API sends live events (server-sent events). The proxy must send each part at once. In Caddy, flush_interval -1 does this. Keep it.

Automatic

sudo bash install.sh zerodot.example.com --proxy caddy

The script does these steps:

  1. It installs Caddy if Caddy is missing. See Install Caddy for the commands for each system.
  2. On Fedora and RHEL with SELinux, it checks if Caddy is confined. If it is, it asks to set httpd_can_network_connect.
  3. It opens ports 80 and 443 in ufw or firewalld, if the firewall is on.
  4. If /etc/caddy/Caddyfile has a block for the domain, the script does not change it.
  5. If the Caddyfile fails caddy validate, the script stops. It prints the block to add by hand.
  6. It makes a copy of the Caddyfile and adds a site block at the end.
  7. It validates the file and reloads Caddy. If Caddy rejects the block, the script puts back the old file.

Caddy gets the certificate when the first request comes in. The DNS record must point to the server.

With --ip (plain HTTP, no domain), the site address is http://<server IP>. The http:// prefix stops Caddy from getting a certificate.

Manual

Install Caddy

Debian and Ubuntu:

sudo apt install -y debian-keyring debian-archive-keyring apt-transport-https curl gnupg
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | sudo gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | sudo tee /etc/apt/sources.list.d/caddy-stable.list
sudo apt update
sudo apt install -y caddy

Fedora:

sudo dnf install -y caddy

RHEL, Rocky and Alma (Caddy is not in their repositories):

sudo dnf install -y 'dnf-command(copr)'
sudo dnf copr enable -y @caddy/caddy
sudo dnf install -y caddy

Arch:

sudo pacman -S --needed caddy

Start Caddy:

sudo systemctl enable --now caddy

Site block for Docker mode

The app listens on 127.0.0.1:3000. If you use another port, change it in the block.

Add this block to the end of /etc/caddy/Caddyfile:

zerodot.example.com {
	encode gzip
	reverse_proxy 127.0.0.1:3000 {
		flush_interval -1
	}
}

Site block for native mode

Native mode has two ports: the web port (default 3000) and the API port (default 3003). The ports of your install are in .zerodot-install (WEB_PORT and API_PORT).

Add this block to the end of /etc/caddy/Caddyfile:

zerodot.example.com {
	encode gzip
	@api path /api/v1/* /api/auth/* /api/p/* /hooks/* /hooks-test/* /resume/* /mcp /mcp/* /oauth2/*
	handle @api {
		reverse_proxy 127.0.0.1:3003 {
			flush_interval -1
		}
	}
	handle {
		reverse_proxy 127.0.0.1:3000
	}
}

The web app can also send the API paths to the API app. Thus a block with one upstream (the web port) also works. The split block is faster, because each API request skips the web app.

Load the block

  1. Validate the file:

    sudo caddy validate --config /etc/caddy/Caddyfile
    
  2. Reload Caddy:

    sudo systemctl reload caddy
    
  3. Open the firewall, if it is on. With ufw:

    sudo ufw allow 80/tcp
    sudo ufw allow 443/tcp
    

    With firewalld:

    sudo firewall-cmd --permanent --add-service=http --add-service=https
    sudo firewall-cmd --add-service=http --add-service=https
    
  4. On Fedora and RHEL with SELinux enforcing, a confined Caddy cannot connect to the app. Set this boolean:

    sudo setsebool -P httpd_can_network_connect 1
    

Caddy runs already

Add the block to the end of the Caddyfile that exists. Do not replace the file.

If the Caddyfile has a log directive with a file, the file must belong to the caddy user. If not, the reload fails. Make the file and set its owner first:

sudo touch /var/log/caddy/zerodot.log
sudo chown caddy:caddy /var/log/caddy/zerodot.log

Caddy in Docker

The installer does not change a Caddy that runs in a container. See Other proxies.

With the Cloudflare proxy

If the DNS record has the orange cloud, see Cloudflare proxy.

Change this page on GitHub