Caddy TLS On-Demand 2026: Dynamic HTTPS with Let's Encrypt

Caddy TLS On-Demand 2026: Dynamic HTTPS with Let's Encrypt

What Is TLS On-Demand in Caddy?

Caddy is famous for making HTTPS easy. Normally, you pre-configure domains, and Caddy automatically fetches and renews certificates from Let’s Encrypt or ZeroSSL.

But what if you don’t know all the domains in advance?

That’s where TLS On-Demand comes in. Instead of requiring you to list every hostname up front, Caddy can request a TLS certificate the moment a client connects.

This is especially useful for:

  • SaaS platforms where customers bring their own domains
  • Multi-tenant apps with dynamic subdomains
  • Hosting providers that serve new domains without manual setup

How TLS On-Demand Works

  1. A client connects to example.com for the first time.
  2. Caddy checks for a cached certificate.
  3. If none exists, Caddy requests one from Let’s Encrypt (or ZeroSSL).
  4. The certificate is stored locally and automatically renewed before expiry.
  5. Future requests serve the cached certificate instantly.

👉 This means no manual certbot scripts or messy cron jobs.

Certificate renewal is handled by Caddy. Separately, task monitoring can track your own backup or maintenance jobs; it does not perform ACME renewal.


Example Caddyfile Configuration

Here’s a simple configuration with on-demand TLS enabled:

{
    on_demand_tls {
        ask https://your-api.example.com/check-domain
    }
}

https:// {
    tls {
        on_demand
    }
    reverse_proxy 127.0.0.1:8080
}

Explanation:

  • on_demand_tls (global option) enables the feature.
  • ask lets you control which domains are allowed by checking against your API.
  • The ask service must authorize only provisioned customer domains. Do not use the removed interval/burst options as a security control.
  • The HTTPS catch-all receives arbitrary hostnames; issuance remains subject to the ask authorization check.
  • Certificates are requested dynamically and then cached for reuse.

Security Best Practices

TLS On-Demand is powerful but can be abused if left open. For example, attackers could point thousands of random domains at your server, exhausting rate limits.

Use an HTTPS monitor to check the served endpoint and certificate expiry, alongside host alerts. A healthy process or open TCP port does not verify certificate issuance.

To stay safe:

  • ✅ Use the ask directive to validate customer domains against your database.
  • The ask service must authorize only provisioned customer domains. Do not use the removed interval/burst options as a security control.
  • ✅ Monitor your certificate logs for unexpected domains.
  • ✅ Keep Caddy updated to benefit from the latest security patches.

Real-World Use Cases

  • Multi-tenant SaaS: Customers get HTTPS automatically on their own domain.
  • Dynamic subdomains: Services like user123.example.com are secured instantly.
  • Reverse proxies: Hosting arbitrary customer domains without manual certs.
  • Self-hosted services: Developers deploying new apps on the fly.

If you're running Caddy in front of Docker, pair it with Docker container monitoring to track each service behind the proxy.


FAQ: TLS On-Demand in Caddy

Q: What is TLS On-Demand in Caddy?
A: It’s a feature where Caddy requests TLS certificates at the moment a client connects, instead of requiring preconfigured domains.

Q: Is TLS On-Demand safe?
A: Yes, as long as you use safeguards like ask validation and rate-limiting to prevent abuse.

A: Caddy integrates certificate management into its HTTPS workflow. Other servers can automate certificates through modules or external tooling; the implementation and operational responsibilities differ.


Key Takeaways

  • TLS On-Demand is ideal for SaaS and dynamic hosting scenarios.
  • Always configure security checks to avoid abuse.
  • With just a few lines of configuration, you can enable automatic HTTPS at scale.

On-demand TLS removes the need to preconfigure every hostname, but issuance still depends on authorization, DNS, challenge reachability, CA limits and durable certificate storage.

To ensure your Caddy server stays healthy beyond just TLS, set up monitoring your Linux servers to track resource usage and uptime.

Validate domain authorization before production

Caddy sends a GET request to the ask endpoint with a domain query parameter. Return a 2xx response only for an exact, normalized hostname that belongs to an authorized tenant; reject unknown domains and fail closed when the lookup is unavailable. Keep this check fast and avoid performing an unbounded remote operation during the handshake.

Check DNS A and AAAA records, supported ACME challenge reachability and persistent Caddy storage. The first connection can take longer while issuance completes. Use a staging CA and a disposable authorized domain to test acceptance and rejection without exhausting production limits, then validate with the same deployed Caddy binary. The global options reference and automatic HTTPS guide describe the current mechanism.