Somes issues from the docs

Hello here !

After watching the github page for month ! I’ve joined the adventure and deployed my first caddy 2 instance ! :grinning:

Still i’ve some issue with the doc. :thinking:

I’m using the latest release of caddy 2

caddy version
v2.0.0-rc.3 h1:z2H/QnaRscip6aZJxwTbghu3zhC88Vo8l/K57WUce4Q=

On the Caddyfile tutorial part (Caddyfile Tutorial — Caddy Documentation) :
When using the template directive with the sample html file the date displayed is still 2006 instead of the date of today as expected.

I have the same issue on Windows or Debian OS

This is the caddy file i used, the same as the docs

localhost

encode zstd gzip
templates
file_server browse

On the log directive part in the documentation (log (Caddyfile directive) — Caddy Documentation)
I want to keep logs for 1 years so i’ve crafted this Caddyfile

domain.name.fr

log {
        output file /var/log/caddy/access.json {
                roll_size 1gib
                roll_keep 5
                roll_keep_for 365 days
        }
}



root * /var/www/bookstack/public

encode zstd gzip

php_fastcgi unix//run/php/php7.4-fpm.sock

file_server

The result ? this seem to not working :thinking:

From the doc it’s saying :

output file <filename> {
	roll_disabled
	roll_size     <size>
	roll_keep     <num>
	roll_keep_for <days>
}

roll_keep_for is how long to keep rolled files. Default: 90 days

From the caddy log :

journalctl -u caddy

Error during parsing: parsing roll_keep_for duration: time: unknown unit days in duration 365days

What is the expected unit ? I am doing wrong ?

Thank ! I hope my remark will help to make better docs !

I think you need to just set roll_keep_for 365 in this case. You’re right that it can be clarified in the docs.

Edit: Made a quick docs PR to fix it:

I’m not sure what the issue is with the templating. I think @matt could clarify.

1 Like

okay, i’ve changed my caddyfile,

This what i get

Caddyfile

log {
        output file /var/log/caddy/access.json {
                roll_size 1gib
                roll_keep 5
                roll_keep_for 365
        }
}

Error :

Error during parsing: parsing roll_keep_for duration: time: missing unit in duration 365

hmm… :thinking:

i’ve seen people using hours instead, so there is different time unit ? this can be added in the docs.

Okay, I’ll look into the log issue a bit more.

Regarding the templates, can you post what contents you put in your html file exactly? I have a hunch but I just want to confirm.

I can confirm this is working when i set in hour insead of days.

Caddyfile :

log {
        output file /var/log/caddy/access.json {
                roll_size 1gib
                roll_keep 5
                roll_keep_for 8760h
        }
}

For the templates part this is what i’ve done :grinning:

Launch command via powershell on Windows 10 1909 :

.\caddy.exe run -watch

Caddyfile :

localhost

encode zstd gzip
templates
file_server browse

html file :

<!DOCTYPE html>
<html>
	<head>
		<title>Caddy tutorial</title>
	</head>
	<body>
		Page loaded at: {<!-- -->{now | date "Mon Jan 2 15:04:05 MST 2006"}<!-- -->}
	</body>
</html>

Result on Microsoft Edge browser :

image

Ah, okay, that’s what I thought. Remove the <!-- --> and it should work. Templates use the {{ }} syntax.

The problem is that the Caddy docs website is also rendered using templates, and if the HTML comments are not there, then the docs would not have that placeholder rendered correctly. I think some change happened to the site that caused the comments to get incorrectly preserved in the rendered markdown. I’ll look into it.

oh this is simple as that ! :thinking:

HTML File ( i’ve played with templates)

<!DOCTYPE html>
<html>
	<head>
		<title>Caddy tutorial</title>
	</head>
	<body>
		<p>The Date of the day is: {{now | date "Mon 2 Jan  15:04:05 CEST 2006"}} </p>
		<p> The Date of the day as timezone is : {{dateInZone "02-01-2006" (now) "CEST"}}
		<p>The WebServer is : {{.Host}} </p>
		<p>Your IP is : {{.RemoteIP}} </p>
		<p>Here some Mutiplication. 2 X 128 = {{ mul 2 128}}
	</body>
</html>

the result :

image

1 Like

Another topic on using Caddy with PHP

I’m running Debian 10 Buster with Caddy, MariaDB and PHP

Apache2 and nginx disabled with ( i’m dunno why apt would install nginx and apache.)

systemctl disable --now apache2
systemctl disable --now nginx

When i enable the php_fastcgi i run this following error

[ERROR 502 /info.php] dial unix/var/run/php/php7.4-fpm.sock connect: permission denied

On the doc for caddy 1 there is a solution to fix the permission
(Troubleshooting PHP FPM and FastCGI · caddyserver/caddy Wiki · GitHub)

So i’ve modified theses files :

/etc/php/7.4/fpm/pool.d/www.conf

listen.owner = caddy
listen.group = caddy

With this fix php is working great :grinning:

Maybe this is better to update the doc on the user creation part and use this instead ? :thinking:

useradd --system \
	--gid www-data\
	--create-home \
	--home-dir /var/lib/caddy \
	--shell /usr/sbin/nologin \
	--comment "Caddy web server" \
	caddy

and change the caddy.service file ?

[Unit]
Description=Caddy
Documentation=https://caddyserver.com/docs/
After=network.target

[Service]
User=caddy
Group=www-data
ExecStart=/usr/bin/caddy run --environ --config /etc/caddy/Caddyfile
ExecReload=/usr/bin/caddy reload --config /etc/caddy/Caddyfile
TimeoutStopSec=5s
LimitNOFILE=1048576
LimitNPROC=512
PrivateTmp=true
ProtectSystem=full
AmbientCapabilities=CAP_NET_BIND_SERVICE

[Install]
WantedBy=multi-user.target

It’s not necessary to have Caddy run as group www-data but the caddy user can easily be added to the user group www-data. Maybe we should add that as a step to the docs for installing as a Linux service.

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