ssl-guides 2026-12-02 ⏱ 3 min read

How to Enable Automatic HTTPS with Caddy

How to Enable Automatic HTTPS with Caddy
Quick Answer: Point your domain's DNS at the server, open ports 80 and 443, and write the domain name in your Caddyfile. Caddy obtains a certificate from Let's Encrypt or ZeroSSL, redirects HTTP to HTTPS and renews before expiry with no extra configuration.

Caddy HTTPS: what it needs

  • The domain's A (and AAAA if used) record points to the server.
  • Ports 80 and 443 are reachable from the internet. Port 80 is used for the HTTP challenge, and 443 for TLS-ALPN.
  • The Caddy process can write to its data directory, so certificates persist across restarts.
  • You use a real hostname. Caddy does not issue public certificates for localhost or IP addresses by default.

A minimal Caddyfile

example.com {
    root * /var/www/example
    file_server
}

That is all. On start, Caddy gets a certificate, serves HTTPS and redirects http://example.com to HTTPS. Apply changes with sudo systemctl reload caddy.

Reverse proxy and www redirect

www.example.com {
    redir https://example.com{uri} permanent
}

example.com {
    encode zstd gzip
    reverse_proxy 127.0.0.1:3000
    header Strict-Transport-Security "max-age=31536000"
}

Caddy passes the right X-Forwarded-* headers by default for reverse_proxy. Apps such as Express still need their trust proxy setting.

Wildcard and internal names

Wildcard certificates need the DNS challenge, which requires a DNS provider plugin built into your Caddy binary:

*.example.com {
    tls {
        dns cloudflare {env.CF_API_TOKEN}
    }
    reverse_proxy 127.0.0.1:3000
}

For private networks, Caddy has an internal CA via tls internal. Browsers will not trust it until you install its root on the client.

Behind Cloudflare

If the record is proxied, the HTTP challenge still works in most setups, but you may hit redirect loops in Flexible mode. Use Full (strict) in Cloudflare, since Caddy provides a valid origin certificate.

Troubleshooting

SymptomLikely causeFix
Challenge failsPort 80 or 443 blocked, DNS not pointing hereOpen ports, fix records, check journalctl -u caddy
Rate limit errorsToo many failed attemptsWait, fix the cause, use staging CA while testing
Certificate not renewingData directory not writable or changedFix permissions, keep storage persistent in Docker volumes
Wrong certificate shownSite block name does not match hostnameMatch the Caddyfile name to the requested host

After it works, verify with the SSL Checker, then check headers with the Security Headers checker.

Running Caddy HTTPS in production

Install it from the official package so the systemd service and a dedicated user are created. Keep the data directory on persistent storage, and back it up, since it holds the account key and certificates. Watch the logs after the first start. In Docker, mount a volume for /data and /config. When testing, switch to the staging CA to avoid hitting rate limits, then remove the setting for the real deployment.

Check the certificate from outside

After the first start, test from another machine rather than on the server: openssl s_client -connect example.com:443 -servername example.com -brief prints the protocol version and says whether the chain verified. A padlock in your own browser proves less, because a local DNS entry or a proxy in front can hide a missing record.

Related reading: free SSL on Railway, Render and Fly.io and HTTPS on Webflow.

Frequently Asked Questions

Does Caddy cost anything?

No, the server and the automatic HTTPS feature are free and open source.

Which CA does Caddy use?

By default it uses Let's Encrypt and ZeroSSL, with fallback between them.

Where does Caddy store certificates?

In its data directory, for example /var/lib/caddy for the Linux service. Keep it on persistent storage.

Can I use my own certificate?

Yes: tls /path/cert.pem /path/key.pem in the site block.

Does Caddy renew certificates on its own?

Yes. It renews before expiry without a cron job, as long as the data directory stays writable and ports 80 and 443 stay reachable.

🔒 Test Your Website SSL Certificate Now
Run Free SSL Check →

✅ Post-Installation Verification & SEO Checklist

After applying the steps above, run through this 5-point checklist to prevent browser warnings and protect your Google SEO rankings:

  • Verify full CA chain trust and TLS 1.3 support using our Live SSL Checker.
  • Scan for Mixed Content HTTP links and check HSTS/CSP headers on Security Headers Checker.
  • Enforce a permanent 301 HTTP-to-HTTPS redirect with our HTTPS Redirect Generator.
  • Confirm both root and www versions resolve cleanly to one canonical HTTPS URL.
  • Verify your HTTPS property and sitemap.xml inside Google Search Console and Bing Webmaster Tools.
Technically Reviewed by TryFreeSSL Security Team
Last updated: 2026-12-05
About Us →

Free SSL Certificates, Live SSL Checker & CSR Generator

Issue trusted Let's Encrypt SSL certificates in 60 seconds with zero server setup.

Related Articles

🤖 TryFreeSSL AI Assistant