If you run a homelab, you know this one. You spin up Pi-hole, a dashboard, Nextcloud, or some internal tool, open it in a browser, and get the big red “Your connection is not private” warning. So you click through it every time, or you fight with self-signed certificates that none of your devices trust.
There’s a better way, and it’s what I run for every private service in my homelab. You get real, publicly trusted certificates from Let’s Encrypt on services that are never exposed to the internet, and you don’t open or forward a single port.
It works by using the DNS-01 challenge with Traefik. In this post I’ll show you how it works and how to set it up.
Why the usual options fall short
Here’s why the common approaches are a pain:
- Self-signed certificates: You have to install your own root certificate authority on every device that touches the service: laptops, phones, a TV, a guest’s machine. That gets old fast, especially on devices you don’t fully control.
- mkcert: Same problem. It’s friendlier than raw OpenSSL, but you’re still distributing a root CA to every client.
- The HTTP-01 challenge: This is the default way Let’s Encrypt verifies you own a domain. The catch is that Let’s Encrypt reaches your server over port 80 from the public internet, so you have to expose your box, which is exactly what we’re trying to avoid.
DNS-01 doesn’t have any of these problems.
How DNS-01 keeps everything private
DNS-01 proves you own a domain a different way. Instead of hitting your server, Let’s Encrypt asks you to create a specific TXT record in your domain’s DNS. It checks that record with your DNS provider, and if it’s there, it issues the certificate.
Let’s Encrypt never connects to your server. So it doesn’t matter that your service lives on a 192.168.x.x address that nobody on the internet can reach.
That means you can use a real domain, like travisdotmedia.xyz, and still keep every service on it private.

What you need
Three things:
- A real domain. Any registrar works, and a
.cloud,.dev, or cheap.comis fine. You just have to own it. - DNS hosted at a supported provider. I use Cloudflare because it’s free and has a solid API. Traefik supports it out of the box, along with dozens of other providers.
- Traefik as your reverse proxy. This is what requests the certificate and terminates TLS in front of your services.
If you haven’t used it, Traefik is a reverse proxy. It sits in front of all your services and routes each request to the right container based on the hostname, so whoami.travisdotmedia.xyz lands on one app and nextcloud.travisdotmedia.xyz lands on another. I like it for a homelab because it discovers your Docker containers automatically and handles Let’s Encrypt certificates for you. You point it at Cloudflare once, and it requests and renews certificates on its own.
You don’t need Kubernetes for any of this. I’ll cover the plain Docker setup first, since that’s what most people want, and then add a short Kubernetes section at the end if you’re running a cluster.
Step 1: Point your domain at Cloudflare
Add your domain to a free Cloudflare account and update the nameservers at your registrar to the ones Cloudflare gives you. This only changes where DNS is answered. It doesn’t expose anything, and your home IP doesn’t go anywhere public.
Step 2: Create a scoped Cloudflare API token
Traefik needs permission to create and delete that TXT record. In the Cloudflare dashboard, go to My Profile, then API Tokens, and create a token from the Edit zone DNS template.
Set the zone resource to your specific domain rather than all zones. The template gives Traefik the two permissions it needs:
- Zone, DNS, Edit
- Zone, Zone, Read
Copy the token somewhere safe. We’ll use it in the next step.
Step 3: The Traefik docker-compose file
Here’s a working Traefik v3 setup. First, save your token to a .env file next to the compose file:
# .env
CLOUDFLARE_DNS_API_TOKEN=your_token_hereTraefik reads the token from CLOUDFLARE_DNS_API_TOKEN (the shorter CF_DNS_API_TOKEN works too). Now the compose file:
services:
traefik:
image: traefik:v3.3
container_name: traefik
restart: unless-stopped
command:
- "--api.dashboard=true"
- "--providers.docker=true"
- "--providers.docker.exposedbydefault=false"
- "--entrypoints.web.address=:80"
- "--entrypoints.websecure.address=:443"
# redirect all http to https
- "--entrypoints.web.http.redirections.entrypoint.to=websecure"
- "--entrypoints.web.http.redirections.entrypoint.scheme=https"
# dns-01 challenge via cloudflare
- "--certificatesresolvers.letsencrypt.acme.dnschallenge=true"
- "--certificatesresolvers.letsencrypt.acme.dnschallenge.provider=cloudflare"
- "[email protected]"
- "--certificatesresolvers.letsencrypt.acme.storage=/letsencrypt/acme.json"
# request one wildcard cert for the whole domain
- "--entrypoints.websecure.http.tls.certresolver=letsencrypt"
- "--entrypoints.websecure.http.tls.domains[0].main=travisdotmedia.xyz"
- "--entrypoints.websecure.http.tls.domains[0].sans=*.travisdotmedia.xyz"
environment:
- "CLOUDFLARE_DNS_API_TOKEN=${CLOUDFLARE_DNS_API_TOKEN}"
ports:
- "80:80"
- "443:443"
volumes:
- "./letsencrypt:/letsencrypt"
- "/var/run/docker.sock:/var/run/docker.sock:ro"A couple of notes:
- The two
tls.domainslines ask for a single wildcard certificate that coverstravisdotmedia.xyzand every*.travisdotmedia.xyzsubdomain. You can only get wildcards with DNS-01, and one cert covers every service you add later. - The
portsare only bound on your LAN host. You aren’t forwarding them on your router, so nothing on the internet can reach them.
Step 4: Test with the staging server first
Let’s Encrypt has rate limits on real certificates (roughly five per domain per week). While you’re getting things working, point Traefik at the staging server so you don’t burn through them. Add this flag to the command list:
- "--certificatesresolvers.letsencrypt.acme.caserver=https://acme-staging-v02.api.letsencrypt.org/directory"Staging issues untrusted test certificates, so your browser will still warn you. That’s fine, since we only want to confirm the challenge succeeds. Once you see the certificate get issued in the Traefik logs, remove that line, delete your letsencrypt/acme.json file, and restart to get the real one.
Step 5: Attach a service
Now let’s put a service behind Traefik. Here’s the whoami test container, so you can confirm everything works before pointing it at your real apps:
whoami:
image: traefik/whoami
container_name: whoami
restart: unless-stopped
labels:
- "traefik.enable=true"
- "traefik.http.routers.whoami.rule=Host(`whoami.travisdotmedia.xyz`)"
- "traefik.http.routers.whoami.entrypoints=websecure"Since we requested the wildcard certificate at the entrypoint level, individual routers don’t need to ask for a certificate. They declare their hostname and Traefik serves them with the wildcard. Adding a new service later only takes a few labels.
Step 6: Make the hostname resolve on your LAN only
This is the step that keeps everything private. The hostname needs to resolve to your Traefik host’s LAN address, and only inside your network. There are two ways to do it:
- Local DNS (my preference): Add a local A record on your Pi-hole or router that points
whoami.travisdotmedia.xyzat your Traefik host, say192.168.1.50. Only devices on your network resolve it. If you already run Pi-hole with Unbound, this takes two minutes in local DNS records. - Private A records in Cloudflare: You can instead add an A record in Cloudflare pointing at your private
192.168.x.xaddress with the proxy turned off. The internet sees a private IP it can’t route to, so nothing is reachable. This does leak the hostname, which is why I prefer local DNS, but it works.
Either way, you haven’t forwarded a port or created a public entry point.
Open https://whoami.travisdotmedia.xyz from a device on your network and you should see a padlock and no warning. You can confirm the issuer from the terminal:
curl -v https://whoami.travisdotmedia.xyz 2>&1 | grep -i issuerYou’ll see Let’s Encrypt as the issuer.
Doing this in Kubernetes with cert-manager
If you run a cluster, the idea is the same but the tooling changes. Traefik doesn’t manage the certificate here. Instead, cert-manager handles the ACME challenge and puts a wildcard certificate into a Kubernetes secret, and Traefik serves it as its default.
First, a ClusterIssuer that uses the Cloudflare DNS-01 solver (store the token in a secret named cloudflare-api-token-secret in the cert-manager namespace):
apiVersion: cert-manager.io/v1
kind: ClusterIssuer
metadata:
name: letsencrypt-cloudflare
spec:
acme:
server: https://acme-v02.api.letsencrypt.org/directory
email: [email protected]
privateKeySecretRef:
name: letsencrypt-key
solvers:
- dns01:
cloudflare:
apiTokenSecretRef:
name: cloudflare-api-token-secret
key: api-tokenThen a Certificate that requests the wildcard and writes it to a secret:
apiVersion: cert-manager.io/v1
kind: Certificate
metadata:
name: travismedia-cloud-wildcard
namespace: traefik
spec:
secretName: wildcard-cert-tls
issuerRef:
name: letsencrypt-cloudflare
kind: ClusterIssuer
dnsNames:
- "travisdotmedia.xyz"
- "*.travisdotmedia.xyz"Finally, tell Traefik to use that secret as its default certificate with a TLSStore:
apiVersion: traefik.io/v1alpha1
kind: TLSStore
metadata:
name: default
namespace: traefik
spec:
defaultCertificate:
secretName: wildcard-cert-tlsFrom there, any IngressRoute on your websecure entrypoint gets the wildcard certificate automatically, and you resolve the hostnames internally just like the Docker setup. If you’re still building out your cluster, my essential homelab apps post pairs well with this.
Common snags
- Wrong env var. A scoped token goes in
CLOUDFLARE_DNS_API_TOKEN(orCF_DNS_API_TOKEN).CF_API_KEYis a different credential: it pairs withCF_API_EMAILfor the older email-plus-key login. - Rate limits. Always test on the staging CA server first, then switch to production.
- DNS propagation delays. If the challenge times out, it’s usually the TXT record not showing up fast enough. Cloudflare is quick, but give it a moment and check the Traefik logs.
- Token scope. If issuing fails with a permissions error, check that your token has Zone DNS Edit on the correct zone.
Conclusion
Once this is running, adding a service is easy. Spin up the container, add a few Traefik labels, add a local DNS record, and you have an HTTPS URL with a valid certificate and no browser warning. It works the same for Nextcloud, a media server, dashboards, or any internal tool.
If you’d rather self-host without a public domain, I also wrote about running Nextcloud locally with no domain at all.
This page may contain affiliate links. Please see my affiliate disclaimer for more info.
