This post will walk through setting up a virtual machine with caddy. We will configure it to use the Cloudflare provider to resolve ACME challenges, enabling us to provision HTTPS certificates through Let’s Encrypt even on private routes.
Caddy Setup
The debian server has a running Caddy (XCaddy for Cloudflare DNS resolution on private wildcard certificates) service.
The Cloudflare Caddy module requires an API token, which we will store into an environment variable CF_API_TOKEN. The JSON payload will have a reference to the environment variable "{env.CF_API_TOKEN}". This will need to be explicitly added into our unit service file.
Configure an account level API token, with Zone.Zone:Read and Zone.DNS:Edit permissions for your domain. Optionally set the token Client IP Address Filtering rule to the Caddy server’s IP.
Edit the systemctl service and add this token to the environment:
sudo systemctl edit caddy
### Editing /etc/systemd/system/caddy.service.d/override.conf ### Anything between here and the comment below will become the new contents of the file [Service] Environment="CF_API_TOKEN=<redacted>"
### Lines below this comment will be discarded
### /etc/systemd/system/caddy.service
# interactive command of json is needed because cloudflare SSH proxy only supports interactive SSH sessions. scp does not work. If you're not using cloudflare zero trust you should be able to just copy this caddy file over to your server. base64 caddy.json | ssh alex@<redacted> 'base64 -d > ~/caddy.json'