1. The problem I’m having:
I’m trying to configure Caddy to reverse proxy from service.domain.tld
to service.internal
(also sub.service.domain.tld
to sub.service.internal
). Here service
should be allowed to be any subdomain and I would like that nothing about the domains is hardcoded in the Caddyfile.
The problem I’m having is that when using regular expressions with the map
directive, I’m unable to use environment variables in the regex. I’m not sure if that should even be supported though. Any ideas how I could do this differently?
2. Error messages and/or full log output:
No errors
3. Caddy version:
2.7.5
4. How I installed and ran Caddy:
a. System environment:
macOS
b. Command:
export ROOT_DOMAIN_EXTERNAL=domain.tld
export ROOT_DOMAIN_INTERNAL=internal
caddy run
d. My complete Caddy config:
:80 {
map {host} {service} {upstream} {
~(.*)\.domain\.tld$ "${1}" "${1}.{$ROOT_DOMAIN_INTERNAL}" # how to do this without hardcoding?
default "root" ""
}
@service expression `{host}.endsWith(r".{$ROOT_DOMAIN_EXTERNAL}")`
handle @service {
reverse_proxy {
dynamic a {upstream} 80
}
}
handle {
respond "root"
}
}