I started working on a multi-tenant system where I had to assign domains on the fly. I was previously using Cloudflare Tunnel, and I have to tell you — it’s a breeze to use. Amazing project. But I like power and don’t want to depend on an opaque dependency, so I started looking into how I could set this system up myself. That’s when I discovered Traefik.
Initially, I faced a lot of issues understanding the configuration combined with the Docker setup, but eventually, I got it.
Let’s say you are serving your app on yourdomain.com, but this app is a multi-tenant app, and you want to separate tenants based on subdomains. So, when a tenant signs up for your service, you want to assign them a subdomain on the fly, or let the new tenant choose a new subdomain.
# Explicitly define cert resolver for both the apex and wildcard domains -"traefik.http.routers.myapp-web.tls.domains[0].main=mydomain.com" -"traefik.http.routers.myapp-web.tls.domains[0].sans=*.mydomain.com"
# Service definition -"traefik.http.services.myapp-web.loadbalancer.server.port=80" restart:unless-stopped networks: -shared_net