Infrastructure · · 1 min read

On-Demand TLS & Multi-Tenant Routing with Caddy and Docker

How Reservasi Online routes custom tenant domains cleanly through a Caddy gateway on Docker—with app-level verification to prevent certificate abuse and proxy loops.

CaddyDockerMulti-TenantDokploy

When building a multi-tenant SaaS booking platform like Reservasi Online, merchants want their own domain or custom subdomain pointing cleanly to their storefront—with automatic HTTPS and zero manual certificate renewal.

Caddy makes on_demand_tls look deceptively simple, until you hit production realities:

  • Certificate abuse: Bots probing random Host headers can trigger unwanted certificate issuance.
  • Internal routing loops: Verification callbacks can accidentally loop back through the public gateway.
  • Worker isolation: Background notification jobs should never share fate with public HTTP workers.

Guarding On-Demand TLS with ask

The core pattern is letting Caddy terminate TLS dynamically only when the application confirms a domain belongs to an active tenant:

{
  on_demand_tls {
    ask http://app:3000/api/domain/verify
  }
}

:443 {
  tls {
    on_demand
  }

  reverse_proxy app:3000
}

Notice the internal upstream target (http://app:3000). Routing the verification callback across the internal Docker network guarantees it never loops back out through the public edge gateway.

Keeping Async Workers Off the Edge

In Reservasi Online, public booking requests stay fast because heavy side effects are pushed off the HTTP path:

  • Email Worker: Decoupled queue processing via BullMQ and Redis.
  • WhatsApp Worker: Internal WAHA container bound strictly to 127.0.0.1 inside the host network, with HMAC-SHA512 webhook signature validation.

Separating edge routing, web rendering, and asynchronous messaging keeps deployments predictable on Docker and Dokploy without needing complex Kubernetes orchestration.

Written by
Salman Fikri — Systems & Product Architect
Founder of PT Epsilon Teknologi Indonesia (Epsitech) · Jakarta, Indonesia
About →

Have Idea for project?

Got some idea and want to realize it?

Contact.