1. The problem I’m having:
Im trying to use environment variables to fill trusted_proxies but not having any luck
2. Error messages and/or full log output:
My Caddyfile is as follows:
{
{$CADDY_GLOBAL_OPTIONS}
}
Running the following I get an error
/srv # CADDY_GLOBAL_OPTIONS="servers {\ntrusted_proxies static 127.0.0.1/8\n}" caddy adapt
2025/10/23 21:44:27.468 INFO using adjacent Caddyfile
Error: parsing caddyfile tokens for 'servers': wrong argument count or unexpected line ending after 'static', at Caddyfile:3
If I change my Caddyfile to be
{
servers {
trusted_proxies static 127.0.0.1/8
}
}
then run
/srv # caddy adapt
2025/10/23 21:45:48.093 INFO using adjacent Caddyfile
{}
2025/10/23 21:45:48.094 WARN caddyfile Caddyfile input is not formatted; run 'caddy fmt --overwrite' to fix inconsistencies {"file": "Caddyfile", "line": 2}
It works fine
Is there something Im missing about how to include envs into Caddyfiles?
I’ve tried this with both “\n” and no “\n”
Of note it also works with:
/srv # CADDY_GLOBAL_OPTIONS="debug" caddy adapt
2025/10/23 21:52:42.770 INFO using adjacent Caddyfile
{"logging":{"logs":{"default":{"level":"DEBUG"}}}}
and
/srv # CADDY_GLOBAL_OPTIONS="debug\
> " caddy adapt
2025/10/23 21:54:01.754 INFO using adjacent Caddyfile
{"logging":{"logs":{"default":{"level":"DEBUG"}}}}
but not
/srv # CADDY_GLOBAL_OPTIONS="servers {\
> trusted_proxies 127.0.0.1/8\
> }" caddy adapt
2025/10/23 21:55:01.759 INFO using adjacent Caddyfile
Error: parsing caddyfile tokens for 'servers': wrong argument count or unexpected line ending after '127.0.0.1/8}', at Caddyfile:3
3. Caddy version:
v2.10.2
4. How I installed and ran Caddy:
Docker