V2 Fails with error. What is wrong with this Caddyfile?

1. My Caddy version (caddy version):

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

2. How I run Caddy:

a. System environment:

$ uname -a
Linux 4.15.0-96-generic #97-Ubuntu SMP Wed Apr 1 03:25:46 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
$ systemd --version
systemd 237
+PAM +AUDIT +SELINUX +IMA +APPARMOR +SMACK +SYSVINIT +UTMP +LIBCRYPTSETUP +GCRYPT +GNUTLS +ACL +XZ +LZ4 +SECCOMP +BLKID +ELFUTILS +KMOD -IDN2 +IDN -PCRE2 default-hierarchy=hybrid

b. Command:

c. Service/unit/compose file:

radd.service in systemd:

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

[Service]
User=caddy
Group=caddy
Restart=on-failure
ExecStart=/usr/bin/caddy run --config /etc/caddy/Raddfile --environ
ExecReload=/usr/bin/caddy reload --config /etc/caddy/Raddfile
TimeoutStopSec=5s
LimitNOFILE=1048576
LimitNPROC=512
#ProtectHome=true // TODO try enabling this
PrivateTmp=true
ProtectSystem=full
AmbientCapabilities=CAP_NET_BIND_SERVICE

[Install]
WantedBy=multi-user.target

d. My complete Caddyfile or JSON config:

/etc/caddy/Raddfile:

https://192.168.196.249 {
    bind 192.168.196.249

    tls internal

   	log {
    	output file /var/log/caddy/ctrl_access.log
   		format single_field common_log
   	}

   	encode gzip zstd

   	handle /spi/* {
   		reverse_proxy localhost:8224
   	}

   	handle {
        root * /var/www/ctrl
   		try_files {path} /index.html
   		file_server
   	}
}

3. The problem I’m having:

I’m trying to run 2 instances of Caddy. This is the one I’m tinkering with and don’t want to disturb the one that is running alpha-production. But this 2nd instance fails with an error. I tried stopping the other instance, but it made no difference.

This instance is bound to a certain vpn network interface with a private IP addr and won’t be exposed to the internet. I’m trying to use the internal CA to get https to work.

4. Error messages and/or full log output:

This error msg seems to be the issue:

Apr 16 21:27:16 caddy[31029]: run: loading initial config: decoding request body: invalid character 'h' looking for beginning of value

Full output via journald:

Apr 16 21:27:16 systemd[1]: Started Radd Web Server.
Apr 16 21:27:16 caddy[31029]: caddy.HomeDir=/var/lib/caddy
Apr 16 21:27:16 caddy[31029]: caddy.AppDataDir=/var/lib/caddy/.local/share/caddy
Apr 16 21:27:16 caddy[31029]: caddy.AppConfigDir=/var/lib/caddy/.config/caddy
Apr 16 21:27:16 caddy[31029]: caddy.ConfigAutosavePath=/var/lib/caddy/.config/caddy/autosave.json
Apr 16 21:27:16 caddy[31029]: runtime.GOOS=linux
Apr 16 21:27:16 caddy[31029]: runtime.GOARCH=amd64
Apr 16 21:27:16 caddy[31029]: runtime.Compiler=gc
Apr 16 21:27:16 caddy[31029]: runtime.NumCPU=1
Apr 16 21:27:16 caddy[31029]: runtime.GOMAXPROCS=1
Apr 16 21:27:16 caddy[31029]: runtime.Version=go1.14.2
Apr 16 21:27:16 caddy[31029]: os.Getwd=/
Apr 16 21:27:16 caddy[31029]: LANG=C
Apr 16 21:27:16 caddy[31029]: PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin
Apr 16 21:27:16 caddy[31029]: HOME=/var/lib/caddy
Apr 16 21:27:16 caddy[31029]: LOGNAME=caddy
Apr 16 21:27:16 caddy[31029]: USER=caddy
Apr 16 21:27:16 caddy[31029]: INVOCATION_ID=f92ae758769a4b27beead6703c12174a
Apr 16 21:27:16 caddy[31029]: JOURNAL_STREAM=9:359724
Apr 16 21:27:16 caddy[31029]: {"level":"info","ts":1587072436.8639393,"msg":"using provided configuration","config_file":"/etc/caddy/Raddfile","config_adapter":""}
Apr 16 21:27:16 caddy[31029]: run: loading initial config: decoding request body: invalid character 'h' looking for beginning of value
Apr 16 21:27:16 systemd[1]: radd.service: Main process exited, code=exited, status=1/FAILURE
Apr 16 21:27:16 systemd[1]: radd.service: Failed with result 'exit-code'.

5. What I already tried:

I’ve tried re-writing the Caddyfile several times, it always complains about the first thing in the file, even if it is a ‘#’. All I did was put a comment as the top line of the file.

Apr 16 21:22:33 caddy[30618]: run: loading initial config: decoding request body: invalid character '#' looking for beginning of value

If I take out the https://' and give it a numeric address e.g. 192.168.196.249 {` it still fails:

Apr 16 21:23:33 caddy[30714]: run: loading initial config: decoding request body: invalid character '.' after top-level value

There is obviously some some really dumb mistake in my Caddyfile, but I just can’t seem to see it. Any help appreciated.

6. Links to relevant resources:

What is Radd and Raddfile? :smile:

Without an --adapter flag, Caddy assumes you are using the native JSON config, unless your file is named Caddyfile (or starts with Caddyfile). This is all documented here: Command Line — Caddy Documentation

Well, I had to have a name that doesn’t collide with the other instance.

But it says I’m "using provided configuration","config_file":"/etc/caddy/Raddfile","config_adapter":"" just like the other one says. Does that not indicate it knows to read it as a Caddyfile?

It doesn’t know what a Raddfile is – you’ll have to rename it to Caddyfile or set the --adapter caddyfile in your command.

Huh… why not just name them differently then? Like Caddyfile1 and Caddyfile2 (or something more descriptive hopefully)?

Because what’s in a name? Or so I imagined.

And because naming it Caddyfile2 looks too much like a version number.

Anyways, now I know. Thanks for pointing out my mistake.

No problem. You don’t have to name it “Caddyfile2” – that was just an example, you could name it something better like “Caddyfile_myapp” or whatever is descriptive. Or you could keep calling it “Raddfile” but then you need to tell Caddy which adapter to use, since it doesn’t know what a “Raddfile” is.

1 Like

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