Caddy v2 environment variables

Hi,

I’ve been reading over the v2 docs relating to the JSON configuration at https://caddyserver.com/docs/json/.

I can’t find anything relating to environment variables support, as available in v1. https://caddyserver.com/v1/docs/caddyfile#env.

Does the JSON configuration support environment variables?

Thanks,
Scott.

1 Like

Great question – yes it does! You can use them as described here: https://caddyserver.com/docs/conventions#placeholders

FYI this is currently in motion, on its way to improvements, so it may not be fully fleshed out yet. e.g. https://github.com/caddyserver/caddy/pull/2963

1 Like

Ah, awesome! Thanks for that.

Is there plans to allow defining environment variables from .env files like it was done for v1? https://github.com/caddyserver/caddy/issues/1941

Thanks a lot for your outstanding work on Caddy!

That’s a good question. Could you open up an issue for this? https://github.com/caddyserver/caddy/issues

In the meantime, I think you could hack this by using a bash script to set the environment before running Caddy. There’s some good ideas for that here: https://stackoverflow.com/a/20909045/846934

2 Likes

Sure, will open an issue in some mins

Meanwhile, I was able to workaround this by using:

set -a
source .env
set +a
caddy run

And might also be able to use tools like npm’s dotenv-cli or ruby’s dotenv

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.