Run caddy as a windows service

1. My Caddy version (caddy version):

v2

2. How I run Caddy:

i use nssm to set up the windows service.

a. System environment:

windows server 2016

b. Command:

start reverse-proxy -host plexrequests.santech.xyz -agree -email=brianwaynesanders@gmail.com -conf c:\caddy\caddyfile -log c:\caddy\serverrun.log

c. Service/unit/compose file:

paste full file contents here

d. My complete Caddyfile or JSON config:

{
email email@mail.com
}

(theheaders) {
header_up X-Forwarded-Ssl on
header_up Host {host}
header_up X-Real-IP {remote}
header_up X-Forwarded-For {remote}
header_up X-Forwarded-Port {server_port}
header_up X-Forwarded-Proto {scheme}
header_up X-Url-Scheme {scheme}
header_up X-Forwarded-Host {host}
}
ombi.mydomain.com {
reverse_proxy http://192.168.0.7:5000 {
import theheaders
}

3. The problem Iā€™m having:

if i run the following in from cmd then caddy works amazingly.

start reverse-proxy -host mydomain.com -agree -email email@mail.com -conf c:\caddy\caddyfile -log c:\caddy\serverrun.log

but if i start the windows service created with nssm it appears that nothing is happening. i canā€™t get to my site and no logs are created. Iā€™ve set the service to run under the same account that iā€™m using when i run this from the cmd line.

4. Error messages and/or full log output:

caddy isnā€™t throwing any logs, nssm stderr.log shows that the caddy server is running but doesnā€™t explain why it works when running from cmd prompt but not in a service.

5. What I already tried:

Iā€™ve tried other methods of creating the service, a different caddyfile, tried using localhost:2019 and still unable to work when running as a service.

6. Links to relevant resources:

Welcome Brian ā€“

I donā€™t use Windows so I donā€™t know much about it, but I can say that your caddy command looks like itā€™s still using the v1 command line arguments and flags, which wonā€™t work.

The v2 command line is documented here: Command Line ā€” Caddy Documentation

All other config goes into your config file.

Hopefully somebody else here knows about the Windows service stuff!

thanks Matt! I stood up an ubuntu box and installed but it didnā€™t like the caddyfile from above. specifically, it barked about ā€œtheheadersā€. I removed that piece but then it wasnā€™t doing the proxy or the ssl piece. the client is working beautifully on windows, I just canā€™t run it as a service.

In case anyone else has this issue I found this resource and itā€™s all working great!!

1 Like

I donā€™t use Windows so I donā€™t know much about it

Just to let you know: The reason that Iā€™m using Caddy, is that it does indeed run on Windows.

Companies that donā€™t have dedicated reverse proxies / load balancers (like Netscaler or other products) are most often running Windows only environments (in my experience).

For them, an easy to install and configure reverse proxy is essential that it can run on Windows.
(Even though it is not your favorite os. :wink:

Now, getting V2 ready is by far the first priority. But Iā€™d think getting a stable platform for Windows is well worth the investment.

NSSM is an option. But I prefer not having too many building blocks. Keep it simple. Make ā€˜caddy startā€™ start the Windows service Caddy Server. :slight_smile:

Cheers,
Vegard

I donā€™t have a ā€œfavorite OSā€ ā€“ I just donā€™t use Windows, regardless of how many companies may use it or like it. :man_shrugging: Feel free to compile a guide to set it up as a Windows service. I donā€™t know how, so I canā€™t do it.

@Brian, NSSM has a good reputation. If you (or anyone else) prefer running Caddy without installing anything extra, it is also possible to use the standard Windows Task Scheduler:

  • Create task
  • On Trigger, you change ā€˜On a scheduleā€™ (at the very top), to ā€˜At startupā€™

I guess it depends on how stable V2 is, running on Windows. As I donā€™t think you get the same restart-on-failure capabilities with Task Scheduler. But is another option with plain Windows.

Vegard

1 Like

If thereā€™s a canonical way ā€“ or maybe two ways ā€“ to set up Caddy as a Windows service, Iā€™ll add it to Install ā€” Caddy Documentation. Just tell me what it is. :stuck_out_tongue:

1 Like

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