I recently decided to start using Coolify for managing the various services I host for myself and others. I had always struggled to maintain an overview over the various services I had deployed on different servers in different ways and hoped that this would help me. I'm currently still in the process of migrating everything, but have been mostly happy with Coolify itself so far. One thing I struggled with however, has been the switch from NGINX to Traefik Proxy, which is used by Coolify for routing to the various services.
In theory Traefik seems like a good tool for managing the sort of task you would usually accomplish by setting up a reverse-proxy with NGINX, only better, since the configuration is not centralized but actually attached to the service you are running through Docker. In practice however, I have found working with it quite difficult, in more ways than one.
My setup involves two main domains, the latter being the shortened version of the first. The idea is that I use jonas-langlotz.de as my canonical URL, while lltz.de can be used as a shorthand which redirects to the full name. This means that for all my services that are reachable through subdomains, I always want the shorthand to expand.
To accomplish this, I decided to add a dynamic configuration file which sets up a generic router for all traffic to my short domain and uses a RedirectRegex middleware to redirect it. This seemed simple enough on paper, but turned out to contain some pitfalls which cost me quite a few hours to fix.
I started out with this basic configuration:
http:
routers:
redirect-router:
rule: "HostRegexp(`{subdomain:.*}lltz.de`)"
middlewares:
- redirect-to-jonas-langlotz
service: noop@internal
entryPoints:
- http
- https
middlewares:
redirect-to-jonas-langlotz:
redirectRegex:
regex: "^(http|https)://(.*?\\.)?lltz.de/(.*)"
replacement: "$${1}://$${2}jonas-langlotz.de/$${3}"
permanent: true
This didn't work