Running as systemd not enough permissions to create logs

1. The problem I’m having:

I installed Caddy as described in the documentation for Debian/RaspbianOS
All went fine without errors.
But when I check the service with systemctl status caddy it shows as running and all is green, but it gives the following errors in the bottom

If I stop the service and run caddy manually with sudo caddy run from the dir where the caddyfile is (etc/caddy/caddyfile) then it just runs as expected.

Removing the log part of the caddyfile and caddy runs without errors.
Should caddy not be able to create files and directories by default?

What permissions should the user and group called caddy have?

2. Error messages and/or full log output:

write error: can't make directories for new logfile: mkdir logs: permission denied

3. Caddy version:

v2.8.4 h1:q3pe0wpBj1OcHFZ3n/1nl4V4bxBrYoSoab7rL9BMYNk=

4. How I installed and ran Caddy:

Install — Caddy Documentation.
follow the documentation to the letter

a. System environment:

Raspberry Pi 5
RaspbianOS/Debian 12

d. My complete Caddy config:

{
	# General Options
	log default {
		output file logs/system.log
		format json
		level debug
	}
	admin :2019

	# TLS Options
	email hostmaster@guldager.one

	# Server Options

}


xn--lovliggr-c5a.nu, www.xn--lovliggr-c5a.nu {
	encode gzip
	reverse_proxy 10.0.0.3
	log {
		output file logs/lovligdk.access.log
		format json {
			time_local
		}
	}
}

xn--lovliggr-c5a.dk, www.xn--lovliggr-c5a.dk {
	encode gzip
	reverse_proxy 10.0.0.3
	log {
		output file logs/lovlig-dk.access.log
		format json {
			time_local
		}
	}
}

lovliggoer.nu, www.lovliggoer.nu {
	encode gzip
	reverse_proxy 10.0.0.3
	log {
		output file logs/lovlig2.access.log
		format json {
			time_local
		}
	}
}

You configured the log path to a relative path

Systemd services default to the root / when the WorkingDirectory is not specified. Change it to something more sensible, e.g. /var/logs/caddy or something, and ensure the caddy user has access to the directory either by group or direct user ACL.

1 Like

Ohh you’r right.

I’m moving caddy from windows to linux, and forgot I could not use the same path.

Thank you for your help

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