A series on building a company's IT with containers and open source
Every service in the lab has a proper name, like grafana.innerbits.example, and a real, trusted HTTPS certificate. Not one of them needs a port forwarded on my router. Most can't be reached from the internet at all. A few can, on purpose.
Getting there took four reverse proxies, a DNS server, a VPN and a tunnel. Grab a coffee.
Reverse proxy speed-dating
The front door changed more often than anything in the lab, except the mail server (post 4, bring tissues):
- Nginx, in front of the first Nextcloud (late 2025)
- HAProxy, with a certificate script (January 2026)
- Nginx again, with a config file that grew one block per app (July 2026)
- Traefik (September 2026), and we're still together
Nginx and HAProxy are excellent. My problem was where the configuration lived. Every new app meant editing the proxy config, reloading it, sorting out a certificate, and remembering to undo all of it when the app left.
With Traefik, routing is a property of the container itself, in its labels:
grafana:
labels:
- traefik.enable=true
- traefik.http.routers.grafana.rule=Host(`grafana.innerbits.example`)
- traefik.http.services.grafana.loadbalancer.server.port=3000
That's it. Defaults on the Traefik side handle HTTPS, certificates and the network. Delete the service, and its route goes with it. It's the first proxy I've used that cleans up after itself.
Certificates without opening anything
Let's Encrypt's usual challenge needs the internet to reach your server on port 80. I didn't want that.
The DNS-01 challenge proves you own the domain by creating a TXT record instead. My DNS is at Cloudflare, Traefik speaks Cloudflare natively, so Traefik gets an API token and issues and renews every certificate without a single inbound packet.
Things that each cost me an evening:
- The token needs Zone Read, not just DNS Edit. Without it, the error is
failed to find zone ... Invalid access token, which sounds like a wrong token and is actually a missing permission. Classic. acme.jsonmust live on a Docker volume. Traefik insists the file is mode 600. A file bind-mounted from Windows is always 755, because Windows has never heard of chmod and isn't interested.- Docker Engine 29 needs Traefik 3.6+. Older releases log a daemon error in a loop and route nothing. Everything looks broken, because everything is.
- Unhealthy containers get Traefik's self-signed default certificate. SonarQube takes about four minutes to become healthy after a restart. For four minutes it looks like a certificate problem. It is not a certificate problem. Go make tea.
- Tokens expire quietly. When the Cloudflare token stops working, nothing breaks at first. Existing certificates keep going for weeks. Then new names get the default certificate, and later renewals fail. Monitor certificate expiry (mine's in Zabbix). Don't rely on remembering.
Names that only exist on my tailnet
Every one of those hostnames points at the host's Tailscale address, so only my devices can reach them. But I don't want those records in public DNS either. A public list of my internal services helps exactly one group of people, and they're not my friends.
The answer is split DNS:
laptop ── "grafana.innerbits.example?" ──> Tailscale: that domain goes to hatchery's DNS
──> Technitium on hatchery ──> "it's the Tailscale IP"
laptop ── HTTPS ──> Traefik on hatchery ──> grafana container
everything else ──> the laptop's normal DNS, as usual
Technitium DNS runs as a container and holds the internal zone. In Tailscale's admin console, a custom nameserver is restricted to innerbits.example. Every other lookup on my laptop goes where it always went.
The zone is a file in Git. A script imports it and replaces every record with the file's contents, so I never edit DNS in the console. There's deliberately no wildcard record. Every service gets its own A record, so a typo fails loudly instead of quietly landing on a 404 and wasting twenty minutes of my life.
Technitium only recurses for loopback, private ranges and Tailscale's range. An open resolver on the internet is a free gift to every DDoS botnet, and it's not even their birthday.
Some things should be public
A company nobody can see isn't much of a company. I wanted a few things reachable from anywhere: the website, webmail, Moodle, the mailing lists, and the analytics tracker.
My home connection sits behind two layers of NAT with a changing IP. Port forwarding wasn't really on the menu.
Cloudflare Tunnel solves it from the other side. A cloudflared container opens an outbound connection to Cloudflare, and Cloudflare sends visitors back down that connection. Nothing listens on my router. My router doesn't even know. My router is blissfully unaware of most things.
The bit I'm proudest of is how the tunnel meets Traefik. Traefik has a second entrypoint called public, on a port that isn't published to the host at all. The tunnel sends everything there. Only routers explicitly labelled for that entrypoint answer. Everything else gets a 404:
- traefik.http.routers.drupal-public.entrypoints=public
- traefik.http.routers.drupal-public.rule=Host(`www.innerbits.example`) && !PathPrefix(`/core/install.php`)
So publishing something takes two deliberate steps, a public router and a tunnel route, and "public" can be narrower than the whole app:
| Public name | What's exposed |
|---|---|
www |
Drupal, minus its installer and update scripts |
webmail |
Roundcube |
moodle |
Moodle |
lists |
Sympa's web interface |
analytics |
only /matomo.js and /matomo.php, never the Matomo UI |
keycloak |
only the sign-in and account pages; /admin is a 404 from outside |
Inside the tailnet nothing changes: Technitium still answers with the Tailscale address, so my devices go direct.
Two lessons, both humbling
Check public access by status code, not by reading your config. I was sure the mailing-list site was public. The config said so. The internet said "Cloudflare error 522", to everyone, for days. My setup script's API token was missing one permission, and a rule it needed had silently never been created. The config was right. Reality disagreed.
Test from outside your own DNS. On the host itself, every lookup for innerbits.example, even one aimed at 1.1.1.1, gets answered with the internal address. To test the public path from inside, I pin the name to a Cloudflare address with curl --resolve. Otherwise you're just testing your own split DNS and congratulating yourself.
Next: mail. Seven setups. Four months. One very patient Cloudflare.
Read next: Company in a Box, Part 4 of 11: Company email on a home internet connection
Comments
Post a Comment