Configure a Caddy reverse proxy with automatic HTTPS
Caddy uses a site address in the Caddyfile to handle requests. When that address contains a domain name, Caddy automatically obtains and renews certificates and redirects HTTP to HTTPS. The reverseproxy directive forwards requests to a backend. This guide configures one public hostname for one HTTP backend and covers prerequisites, verification, and failure diagnosis. Local development certificates, Kubernetes, multiple backends, and advanced TLS policy are out of scope.
Caddy uses a site address in the Caddyfile to handle requests. When that address contains a domain name, Caddy automatically obtains and renews certificates and redirects HTTP to HTTPS. The reverse_proxy directive forwards requests to a backend. This guide configures one public hostname for one HTTP backend and covers prerequisites, verification, and failure diagnosis. Local development certificates, Kubernetes, multiple backends, and advanced TLS policy are out of scope.
Prerequisites
Use a domain you control. Its A and/or AAAA records must point to the public address of the Caddy server, and the server must be reachable on external ports 80 and 443. The application must be running at an address Caddy can reach. 127.0.0.1:9000 below assumes the backend runs on the same host. Binding to ports 80 and 443 may require OS-specific service permissions; do not default to running Caddy as root.
app.example.com {
reverse_proxy 127.0.0.1:9000
}Replace app.example.com and the upstream with your real values. The example domain cannot obtain a public certificate. A hostname in the site address triggers automatic HTTPS; public certificates also require a publicly valid domain and working network path for the certificate authority. Local names and IP addresses use different certificate conditions.
Format and validate before starting:
`caddy fmt --overwrite Caddyfile` formats the file and overwrites it. Keep the file in version control or a backup.
`caddy validate --config Caddyfile` loads and provisions the config to catch errors, but does not run the server or prove DNS, firewall, certificate issuance, or backend connectivity. Provisioning can acquire resources, so avoid validating a second process against resources held by a running instance. For a live config change, use the approved `caddy reload` workflow.
In a test environment, run `caddy run --config Caddyfile`; it stays in the foreground. Production deployments should use the platform's service manager and log policy.
Request `curl -i https://app.example.com/`. A response from the application verifies the public TLS path and proxy route together.
Diagnose and recover
Certificate issuance or renewal fails: confirm A/AAAA records, public reachability on ports 80/443, firewall rules, port forwarding, and DNS provider settings. A successful config validation does not prove ACME will succeed.
502/503 or connection refused: confirm the upstream address is valid from Caddy's host, the application listens on that port, and containers share a reachable network. Check both Caddy and application logs.
The request reaches the wrong site: check DNS, port conflicts, and whether the site address matches the request Host.
A config change breaks the service: preserve the last known-good Caddyfile and restore it through the approved deployment process. After `caddy reload`, inspect logs and make a real HTTPS request to confirm the active config.
When Caddy sits behind a CDN or another proxy, configure only the trusted proxy CIDR ranges before trusting forwarded client IP headers. A directly internet-facing Caddy instance should not trust arbitrary incoming X-Forwarded-* values.
Sources read 2026-11-19: HTTPS quick-start, reverse-proxy quick-start, Automatic HTTPS, reverse_proxy directive, and command line. The example was not run; no domain, certificate, network, or backend was configured or tested.