I installed Caddy via the recommended way for ubuntu. It was running fine (when I did curl localhost:80) and systemctl status caddy reported Caddy was active. Then I edited my Caddyfile to use my custom domain name and also activate metrics and expvar, and when I did systemctl reload caddy it returned with a failed status
2. Error messages and/or full log output:
systemctl reload caddy
Job for caddy.service failed.
See "systemctl status caddy.service" and "journalctl -xeu caddy.service" for details.
root@ubuntu-2gb-nbg1-1:/# journalctl -xeu caddy.service
Feb 13 13:58:30 ubuntu-2gb-nbg1-1 caddy[13366]: {"level":"info","ts":1707832710.969163,"logger":"admin.api","msg":>
Feb 14 13:37:29 ubuntu-2gb-nbg1-1 caddy[13366]: {"level":"info","ts":1707917849.239912,"logger":"tls","msg":"clean>
Feb 14 13:37:29 ubuntu-2gb-nbg1-1 caddy[13366]: {"level":"info","ts":1707917849.2401817,"logger":"tls","msg":"fini>
Feb 14 15:06:16 ubuntu-2gb-nbg1-1 systemd[1]: Reloading Caddy...
░░ Subject: A reload job for unit caddy.service has begun execution
░░ Defined-By: systemd
░░ Support: http://www.ubuntu.com/support
░░
░░ A reload job for unit caddy.service has begun execution.
░░
░░ The job identifier is 5465.
Feb 14 15:06:16 ubuntu-2gb-nbg1-1 caddy[21666]: {"level":"info","ts":1707923176.7104475,"msg":"using provided conf>
Feb 14 15:06:16 ubuntu-2gb-nbg1-1 caddy[21666]: Error: adapting config using caddyfile: server block without any k>
Feb 14 15:06:16 ubuntu-2gb-nbg1-1 systemd[1]: caddy.service: Control process exited, code=exited, status=1/FAILURE
░░ Subject: Unit process exited
░░ Defined-By: systemd
░░ Support: http://www.ubuntu.com/support
░░
░░ An ExecReload= process belonging to unit caddy.service has exited.
░░
░░ The process' exit code is 'exited' and its exit status is 1.
Feb 14 15:06:16 ubuntu-2gb-nbg1-1 systemd[1]: Reload failed for Caddy.
░░ Subject: A reload job for unit caddy.service has finished
░░ Defined-By: systemd
░░ Support: http://www.ubuntu.com/support
░░
░░ A reload job for unit caddy.service has finished.
░░
░░ The job identifier is 5465 and the job result is failed.
lines 48-76/76 (END)
PASTE OVER THIS, BETWEEN THE ``` LINES.
Please use the preview pane to ensure it looks nice.
c. Service/unit/compose file:
PASTE OVER THIS, BETWEEN THE ``` LINES.
Please use the preview pane to ensure it looks nice.
d. My complete Caddy config:
cabincrewforyou.com {
# Set this path to your site's directory.
root * /var/www/html
# Enable the static file server.
file_server
# Another common task is to set up a reverse proxy:
# reverse_proxy localhost:8080
# Or serve a PHP site through php-fpm:
# php_fastcgi localhost:9000
}
{
servers {
metrics
}
}
expvar
I got Caddy to run again after reducing the Caddyfile to a bare minimum
> cabincrewforyou.com {
> # Set this path to your site's directory.
> root * /var/www/html
>
> # Enable the static file server.
> file_server
>
> # Another common task is to set up a reverse proxy:
> # reverse_proxy localhost:8080
>
> # Or serve a PHP site through php-fpm:
> # php_fastcgi localhost:9000
> }
However, I do wish to add server metrics and also expvar. So can someone please explain how to do this, as the resource linked to by @francislavoie is not clear to me. Maybe I’m not experienced enough, but there appear to be other contradictory resources on the caddy documention page. Thanks to anyone who can help.
Please use code blocks when posting your config. It’s very difficult to read otherwise. Use the </> button. Code blocks start and end with ``` on their own lines.
Global options must go at the top of your Caddyfile, as explained by the structure diagram.
I don’t know what expvar is, that’s not something built-in to Caddy. Can you elaborate? Ah, you mean the /debug/vars endpoint of the admin API.
It’s enabled by default, just make requests to Caddy’s admin API http://localhost:2019/debug/vars
thank you @francislavoie . Before I make the change to my file in production, can you please confirm this is what is meant by how to add a global config option. Does metrics need to be inside the nested json structure like this?
{ servers
{
metrics
}
}
cabincrewforyou.com {
# Set this path to your site's directory.
root * /var/www/html
# Enable the static file server.
file_server
# Another common task is to set up a reverse proxy:
# reverse_proxy localhost:8080
# Or serve a PHP site through php-fpm:
# php_fastcgi localhost:9000
}
I’m surprised expvar is enabled by default. I personally don’t mind but I thought there was a possibility that it was private information. In fact, I saw a warning in (old) Caddy documentation about the ‘risk’ of exposing expvar to the public.
The admin API is not publicly accessible (and should not be configured to be). If it was, then an attacker could change your server’s config and do bad things.