Cloudflare: Caddyfile:8: unrecognized directive: dns

1. Caddy version (caddy version):

v2.0.0 h1:pQSaIJGFluFvu8KDGDODV8u4/QRED/OPyIR+MWYYse8=

2. How I run Caddy:

I currently run caddy in my homedir with:

./caddy run --config Caddyfile

a. System environment:

macOS Catalina, latest version

b. Command:

xcaddy build --with github.com/caddy-dns/cloudflare
./caddy run --config Caddyfile

d. My complete Caddyfile or JSON config:

{
    debug
    email <redactd>
    experimental_http3
}

tls {
    dns cloudflare {env.CLOUDFLARE_API_TOKEN}
}

code.example.no {
    reverse_proxy 127.0.0.1:8080
}

3. The problem Iā€™m having:

I am trying to start caddy with my configuration, but I get a configuration error which I cannot seem to figure out. The configuration is from the last example on this page: tls (Caddyfile directive) ā€” Caddy Documentation

2020/05/07 20:56:39.250	INFO	using provided configuration	{"config_file": "Caddyfile", "config_adapter": ""}
run: adapting config using caddyfile: Caddyfile:8: unrecognized directive: dns

4. Error messages and/or full log output:

See 3.

Hi @kradalby, welcome to the Caddy community!

Please note some of the pointers from the Caddyfile documentation:

  • An optional global options block can be the very first thing in the file.
  • Otherwise, the first line of the Caddyfile is always the address(es) of the site to serve.
  • All directives and matchers must go in a site block. There is no global scope or inheritence across site blocks.

ā€”Caddyfile Concepts ā€” Caddy Documentation

You have placed the tls directive outside of a site block.

Therefore, Caddy is interpreting tls as the site label (the name of the site you want to serve), and is trying to interpret dns as a directive for configuring that site. As the error notes, dns is not a directive, so this causes a problem.

The examples in the tls documentation are intended to go inside a site block.

2 Likes

ah thank you @Whitestrake, that worked.

I was sure I had tried that, but I must have seen myself blind in a brute force attempt.

1 Like

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