Pcornel
Browse topics
Options
Recent
Favorites
Web Infrastructure · Technical reference

Caddy

Direct answer

Caddy is a web server and reverse proxy written in Go whose defining feature is automatic HTTPS: it obtains and renews certificates via ACME and redirects HTTP to HTTPS without extra configuration.

When to use this

Use it when you want a simple, secure-by-default web server or reverse proxy, especially for small sites, internal tools and containers where certificate management should just work.

First 30 seconds

1. Does the config validate?

2. Did certificate issuance succeed (journal)?

3. Are 80/443 reachable from the internet (or is DNS challenge configured)?

4. Is the data directory persistent and writable?

Operational verification

Caddyfile → adapted to JSON → running config (admin API) → automatic HTTPS (ACME, storage) → site routes (reverse_proxy, php_fastcgi, file_server)

Context & applicabilityCommon mistakes · platform/version boundaries
Platform / version applicability
Caddy 2.x.
Applicability is projected only from persisted Topic profile and Command metadata.
At a glance

Operational reference

Fast context before you go deeper.

PlatformCaddy 2.x.
Key commandsystemctl status caddy
Scope / prerequisiteUse it when you want a simple, secure-by-default web server or reverse proxy, especially for small sites, internal tool…
What next?2 suggested next steps
Evidence0
On this pageJump to a specific section
Operational workflow

Verification & Troubleshooting

Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.

3 steps Observe → verify → isolate → change minimally → repeat the original test.
ObservedRecord what the original test actually shows

Capture the concrete output, symptom, packet, log or counter before changing anything.

Step 1 Read-only Verification Verify boundary
caddy validate --config /etc/caddy/Caddyfile
systemctl status caddy
journalctl -u caddy --since "1 hour ago" | grep -iE 'certificate|obtain|error'

# Running configuration (admin API on localhost)
curl -s localhost:2019/config/ | jq '.apps.http.servers | keys'

# From outside: redirect and certificate
curl -sSI http://example.com/ | head -3
echo | openssl s_client -connect example.com:443 -servername example.com 2>/dev/null | openssl x509 -noout -issuer -dates

The journal logs each certificate obtain/renew attempt with the challenge type and the CA's error if it fails.

Step 2 Common mistakes Narrow the fault
  • Running Caddy in a container without persistent storage for certificates.
  • Enabling on-demand TLS without an ask restriction.
  • Exposing the admin API beyond localhost.
  • Putting Caddy behind another TLS-terminating proxy and still expecting HTTP-01 to work.
Step 3 Troubleshooting Narrow the fault

Certificate cannot be obtained. Port 80/443 not reachable from the internet, DNS not pointing to this server, a CDN or proxy in front intercepting the challenge, or CA rate limits after repeated failures. Use the DNS challenge for servers that are not publicly reachable.

New certificates on every restart. The data directory is not persistent (container without a volume, wrong HOME for the service user).

Reverse proxy returns 502. Upstream unreachable or failing active health checks (health_uri); the journal shows the dial error.

Config change has no effect. It was edited but not reloaded, or the reload failed validation — check journalctl -u caddy.

Key points

A site address with a hostname turns on automatic HTTPS. Caddy needs ports 80 and 443 reachable (or DNS challenge) to get certificates, and a persistent data directory to keep them. Validate before reload: caddy validate, then caddy reload.

Key checks
  • caddy validate --config /etc/caddy/Caddyfile — config is valid.
  • systemctl status caddy and journalctl -u caddy — startup and certificate issuance messages.
  • curl -s localhost:2019/config/ | jq — running configuration via the admin API.
  • curl -sSI https://<host>/ — certificate and redirect working.
ReferenceWhat it is2 sections · depth on demand

Direct Answer

Caddy is a web server and reverse proxy with automatic HTTPS. As soon as a site address contains a hostname, Caddy obtains a certificate from an ACME CA (Let's Encrypt, with ZeroSSL as fallback), renews it, and redirects HTTP to HTTPS. A short Caddyfile covers most sites, HTTP/2 and HTTP/3 are on by default, and the running configuration can be read and changed through a local admin API.

Source basisSource attribution states what this section is based on; it is not independent proof that the current environment matches it.
ReferenceImportant terms & boundaries1 section · depth on demand

In depth

Caddyfile

{
    email admin@example.com
}

example.com, www.example.com {
    root * /var/www/example
    encode zstd gzip
    php_fastcgi unix//run/php/php8.2-fpm.sock
    file_server
}

app.example.com {
    reverse_proxy 10.0.0.21:8080 10.0.0.22:8080 {
        lb_policy least_conn
        health_uri /healthz
    }
}

The global options block (first braces) sets account email and defaults. Each site block starts with its addresses. Directives such as reverse_proxy, php_fastcgi, file_server, encode, header, redir and handle/route are ordered by Caddy's built-in directive order unless grouped explicitly.

Automatic HTTPS

AspectBehaviour
TriggerA hostname or IP in the site address
IssuersLet's Encrypt first, ZeroSSL as fallback
RedirectsHTTP on port 80 redirected to HTTPS automatically
ChallengesHTTP-01 needs port 80, TLS-ALPN-01 needs 443; DNS challenge needs a DNS provider module and credentials but no open ports
Local nameslocalhost and internal names get certificates from Caddy's own local CA
StorageData directory (needs a writable, persistent $HOME/XDG_DATA_HOME); instances sharing storage coordinate as a cluster
RenewalAutomatic in the background; failed attempts retry with backoff
On-demand TLSCertificates obtained at the first handshake for unknown names — must be restricted with an ask endpoint

In containers, mount the data directory on a volume; losing it forces new certificate orders on every restart and can hit CA rate limits.

Configuration model and admin API

The Caddyfile is adapted to Caddy's native JSON. The admin API on localhost:2019 exposes and changes the running configuration (/config/); caddy reload pushes a new config through it without downtime. Keep the admin endpoint bound to localhost.

Commands

CommandPurpose
caddy validate --config <file>Check the configuration
caddy fmt --overwrite <file>Normalise Caddyfile formatting
caddy adapt --config <file>Show the resulting JSON
caddy reload --config <file>Apply without downtime
caddy list-modulesInstalled modules (e.g. DNS providers)
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Terminology layer

Terms & aliases

Hover a linked term for a quick definition; click it to open its glossary entry. Aliases are other names that find this Topic in search.

Aliases that resolve here
caddycaddyfilecaddy reverse_proxycaddy automatic https
Confirmation

Confirm action

Continue?