Unrecognized directive: dns

Thank you so much @SlothCroissant for your Docker Image!

However I am not able to get it up and running. I keep getting these errors below. Sorry, completely new to Caddy!

{“level”:“info”,“ts”:1589436903.8301146,“msg”:“using provided configuration”,“config_file”:"/etc/caddy/Caddyfile",“config_adapter”:“caddyfile”}

run: adapting config using caddyfile: /etc/caddy/Caddyfile:2: unrecognized directive: dns

This is what I have tried in my Caddyfile:

tls myemail@email.com {
dns cloudflare {env.CLOUDFLARE_API_TOKEN}
}

wiki.{$MY_DOMAIN} {
reverse_proxy 192.168.20.10:80
}

Hi @wotig1313, welcome to the Caddy community!

I moved your post to a new thread so we can address your question.

The first line in your Caddyfile should be the site you want to serve. (Or a global options block, but that’s an exception.)

With your Caddyfile, Caddy is reading that as you wanting to serve sites called tls and myemail@email.com, and within that site you’re trying to configure a directive called dns.

There is no dns directive, though! But there is a directive called tls, and it’s meant to go inside your site configuration.

So what you need to do is take that entire tls section, indent it, put it inside your site configuration, and give that a shot.

Thanks for your advice! I’m totally new to Caddy, so please bear with me.
Is this correct?

example.com {

{
tls my email address {
dns cloudflare {env.CLOUDFLARE_API_TOKEN}
}

wiki.{$MY_DOMAIN} {
reverse_proxy 192.168.20.10:80
}

No worries! Happy to help.

That doesn’t look right, though, I’m afraid. You open two brace blocks but never close them:

image

And, you want Caddy to use the DNS challenge for your wiki subdomain, right?

Start a site config with your site label (i.e. wiki.{$MY_DOMAIN}), open the brace block, then put the whole tls directive inside it, indented. Like, on a new line directly before or after your reverse_proxy.


P.S.: Encase your configs as code blocks - use the preformatted text button up the top or encase them in triple backticks (```) to preserve indentation so it’s easier to read.

image

1 Like

Ok. So then like this?
Yes, I do want to use the DNS Challenge for my Wiki. Docker and all containers including Caddy are on one VM and the Wiki is on another VM altogether.

example.com {
}

tls my email address {
dns cloudflare {env.CLOUDFLARE_API_TOKEN}
}

wiki.{$MY_DOMAIN} {
reverse_proxy 192.168.20.10:80
tls my email address
dns cloudflare {env.CLOUDFLARE_API_TOKEN}
}

Not quite!

2 Likes

Ok. How about now?

{
wiki.{$MY_DOMAIN} {
reverse_proxy 192.168.20.10:80 }
tls my email address {
dns cloudflare {env.CLOUDFLARE_API_TOKEN} }
}

Heh, where’d all those extra braces come from?

Have a closer look at the Caddyfile structure:

Look especially at the visual aide and the examples in the Block section.

Sorry, it is still going above my head. I’ve gone through the documentation multiple times. I work better with actual examples, which I can copy and adapt to fit my usecases.

Would be great if you could just format this one correctly, so that I know exactly how it is supposed to look like. :slight_smile:

Should be like this:

wiki.{$MY_DOMAIN} {
  tls email@example.com {
    dns cloudflare {env.CLOUDFLARE_API_TOKEN}
  }
  reverse_proxy 192.168.20.10:80
}

The actual examples are right here in the Blocks section I mentioned in my previous comment.

1 Like

Ok, thank you very much! WIll try this soon and also test my other services. :smiley:

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