Troubleshoot Caddy 502 Errors and HTTPS Certificate Failures
Before you begin
- Applies to:Caddy deployments where clients receive HTTP 502 or cannot establish HTTPS.
- Where to start:Start from an affected client using the exact URL. Then check the proxy host and the backend connection separately.
- What you need:Record the hostname, error, time, and expected backend address. Keep certificate validation enabled.
Guide tools
Use this guide when clients see a 502 response or cannot establish HTTPS. A 502 received over verified HTTPS indicates the client reached an HTTP endpoint. Start by checking whether Caddy or an intermediary returned it, then trace the proxy-to-app connection separately.
Before You Start
Caddy v2 using the caddy systemd unit and a Caddyfile on Ubuntu 26.04 LTS. The examples assume a local HTTP application listening on port 8080 and a publicly addressed HTTPS hostname. Use curl, dig from dnsutils, and sudo access for the Caddy host checks. Replace example account names, paths, hostnames, ports and service names with your own values. Run the steps in order, using the same shell for blocks that share variables.
Troubleshooting Steps
Check the public hostname from an affected client
ClientReplace app.example.com with the exact affected name and use a known read-only endpoint. Inspect A and AAAA answers for stale addresses and compare them with the intended origin or proxy. If you see a certificate error, check the hostname, issuer, trust chain, client time and expiry. If you see 502, record the time and response headers.
dig +short A app.example.comdig +short AAAA app.example.comcurl -v --connect-timeout 5 --max-time 12 https://app.example.com/healthTest the upstream from the Caddy host
UpstreamUse the scheme and address specified in the reverse_proxy directive. In this example the app should answer on loopback port 8080. A refusal suggests a missing listener or wrong port. A timeout suggests a path or service issue. For HTTPS upstreams use the configured hostname and trust chain. If Caddy runs in a container, test from its network context.
curl -v --connect-timeout 3 --max-time 8 http://127.0.0.1:8080/healthsudo ss -ltnp 'sport = :8080'sudo journalctl -u caddy --since '20 minutes ago' --no-pagerCheck certificate issuance separately
TLSRead the Caddy logs around the failed issuance or renewal. Confirm the site address matches the affected hostname and check reachability for the configured challenge. HTTP-01 needs port 80, TLS-ALPN-01 needs port 443, and DNS-01 depends on its DNS provider configuration. Use systemctl cat to identify the actual service config path and run validation with its required files and environment.
systemctl cat caddysudo ss -ltnp '( sport = :80 or sport = :443 )'sudo caddy validate --config /etc/caddy/Caddyfile --adapter caddyfileApply the narrow fix and verify both paths
RecoveryRestore the correct upstream, listener, DNS record, certificate dependency, or challenge route. Back up the known-good Caddyfile before editing. After successful validation reload the unit only if you changed Caddy configuration. If the change regresses, restore the backed-up config, validate, and reload. Verify the public endpoint from the original client after DNS changes propagate.
# On the Caddy host after approved configuration changessudo caddy validate --config /etc/caddy/Caddyfile --adapter caddyfile && sudo systemctl reload caddy
# Run from the affected client and expect the application health responsecurl --fail --show-error --connect-timeout 5 --max-time 12 https://app.example.com/healthReferences
Your feedback keeps these production procedures accurate and battle-tested.