Caddy as an NSSM service

1. Caddy version (caddy version):

2.3.0

2. How I run Caddy:

I currently run it through cmd on windows 10 - caddy start

a. System environment:

Windows 10, caddyfile

3. The problem I’m having:

I’m wondering how caddy can be installed as a service using nssm, to use the Caddyfile, instead of providing arguments. Or is this not possible?

1 Like

You can specify command args when installing a service with NSSM.

Simply specify the --config flag.

1 Like

My NSSM setup looks like this:

.\nssm.exe install caddy C:\path\to\caddy\caddy.exe
.\nssm.exe set caddy AppParameters "run --environ --config Caddyfile --watch"
.\nssm.exe set caddy AppDirectory C:\path\to\caddy
.\nssm.exe set caddy AppExit Default Restart
.\nssm.exe set caddy AppNoConsole 1
.\nssm.exe set caddy AppStdout C:\path\to\caddy\stdout.log
.\nssm.exe set caddy AppStderr C:\path\to\caddy\stderr.log
.\nssm.exe set caddy AppTimestampLog 1
.\nssm.exe set caddy Description "Caddy Server"
.\nssm.exe set caddy DisplayName Caddy
.\nssm.exe set caddy ObjectName LocalSystem
.\nssm.exe set caddy Start SERVICE_AUTO_START
.\nssm.exe set caddy Type SERVICE_INTERACTIVE_PROCESS
2 Likes

I’ve tried both creating my own and using --config to point to the Caddyfile, and the NSSM cmd line set up, both of which get the below whenever I try to start the service:

Your user probably needs to be an administrator to be able to bind to ports 80 and 443, probably. Services can be finicky on Windows.

My user is an administrator, however the service is set to “log on as” Local System. I did just set the log on as to myself but it’s still giving me this same error.

Have you redirected stdout and stderr to log files?

If so, is there anything in there?

Caddy’s pretty much always got something to say, even if it can’t start up - might point us in the right direction on why it’s not working in your case.

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