Is this Caddyfile syntax invalid, or is it a bug?

1. Caddy version (caddy version):

v2.5.2

2. How I run Caddy:

a. System environment:

Debian Bullseye

b. Command:

systemctl start caddy

c. Service/unit/compose file:

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

[Service]
User=caddy
Group=caddy
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

d. My complete Caddyfile or JSON config:

(nested) {
	header server pseudo
}

(problem) {
	import nested
	reverse_proxy {args.0}
}

(serve) {
	handle {
		import problem {args.0}
	}
}

www.example.com {
	import serve 10.10.10.10:8080
}

3. The problem Iā€™m having:

The above Caddyfile only validates when the ā€œimport nestedā€ line is commented out, or when the handle block is stripped from (serve). I would like to find out if this is by design, or due to a bug that affects nesting.

4. Error messages and/or full log output:

validate: adapting config using caddyfile: parsing caddyfile tokens for ā€˜handleā€™: Caddyfile:13 - Error during parsing: unrecognized directive: import - are you sure your Caddyfile structure (nesting and braces) is correct?

5. What I already tried:

I have reduced a very complex Caddyfile to the crux of the issue.

6. Links to relevant resources:

Huh, interesting. Iā€™d probably call it a bug. But Iā€™m not sure why that happens. The import should already be expanded before handle gets to see it. Iā€™ll need to investigate further.

Feel free to open an issue on github for this :+1:

1 Like

Thanks, Iā€™ll do just that.

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