I have multiple configs for each app (subdomain). My goal is not touching the config file for multiple domains. I want to define the different domain names via an environment variable.
At the moment i define my apps for a domain like this. So i can specify the domain name via environment var.
app1.{$BASE_DOMAIN} {
...
}
This is working fine, but i have several host that have multiple (alternative) domain-names that should serve the same apps.
At this point, I would probably look at something like dockerize to see if it can template the Caddyfile the way you want. Then run dockerize shortly before starting Caddy so it generates the final Caddyfile from a template.
Dockerize is meant for templating inside Docker containers, but you can also use it outside containers. It is a relatively small Golang app.
Another option is to write a simple shell script that generates the final Caddyfile based on your criteria before launching Caddy.