Environment Variables in Windows 10

So I’m able to get the environment variables I set in the command prompt to work for Cloudflare when I run caddy from the command prompt. However, when I have Caddy start as a nssm service, it seems that caddy does now have those variables and Cloudflare gives a Error 522 that caddy isn’t responding.

Anyone know of a way to pass those variables in a way that nssm can use them being a service wrapper???

Just set the Environment variables in Windows System Properties → Advanced → Environment Variables or if you prefer to do this with the cmd line use:

setx CLOUDFLARE_EMAIL xxxxxxx@emailprovider.com
setx CLOUDFLARE_API_KEY myapikeyxxxxxxxx

So I did that and it works fine when running from Caddy from the command prompt. However, the same variables when running as a service via nssm does not work.

So I don’t know how to set the variables for nssm to know to use them.

This seems like an nssm issue and for some reason it’s not able to start caddy. Does it run when you take out the the code for cloudflare DNS and just use a basic caddyfile?

Caddy stores the certs in the users account folder so maybe you need to run it under your account and not have it run under default “Local System Account”.

1 Like

Yea it runs fine using just a regular ddns and no “provider” dns.

So if I have nssm run under user account you think it’ll work?

I did a quick test and couldn’t get nssm to run caddy with my site unless I ran it under my user account but YMMV.

I’m running Caddy using NSSM and it’s working fine for me with environment variables.

I went to the “Environment Variables” dialog from the “System” settings in the control panel, and I put the environment variables I wanted into the “System variables” section, not the “User variables for X” section.

Alternatively when you set up the service, NSSM has a tab called “Environment” that you can use to set any environment variables for your service. All you need to do is run:

nssm edit your_service_name

Then keep on clicking the right arrow where the tabs are until you see the “Environment” tab on the end.

I got it working. Thanks all.

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