Caddy v2 environment variables


I’ve been reading over the v2 docs relating to the JSON configuration at

I can’t find anything relating to environment variables support, as available in v1.

Does the JSON configuration support environment variables?


1 Like

Great question – yes it does! You can use them as described here:

FYI this is currently in motion, on its way to improvements, so it may not be fully fleshed out yet. e.g.

1 Like

Ah, awesome! Thanks for that.

Is there plans to allow defining environment variables from .env files like it was done for v1?

Thanks a lot for your outstanding work on Caddy!

That’s a good question. Could you open up an issue for this?

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:


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.