How to use DNS provider modules in Caddy 2

Caddy 2 uses a new and improved DNS provider interface for solving the ACME DNS challenge.

All you have to do is plug the service provider(s) you need into your build, then add the DNS challenge to your configuration!

Getting a DNS provider plugin

How you choose to get a custom Caddy build is up to you; we’ll describe two common methods here.

Method 1:

  1. Go to the Caddy download page.
  2. Find your DNS provider in the list of modules (dns.providers.*) and select it.
  3. Download your custom Caddy build.

Method 2:

  1. Find your DNS provider in the caddy-dns repositories.
  2. Build caddy with your DNS provider plugged in. This is a single xcaddy command:
    xcaddy build --with github.com/caddy-dns/REPOSITORY
    

If you do not find your DNS provider:

If you do not find a module for your DNS provider, that means nobody has implemented it yet. Your DNS provider must be implemented, either by you or someone else kind enough to do it. We can do it for your business for free with a Business+ sponsorship or higher.

Enabling the DNS challenge

Once you have a custom Caddy binary with your DNS provider module plugged in, you simply have to enable the DNS challenge in your config. Do this one of the following ways:

Caddyfile

Global option (use DNS challenge for all sites)

For a globally-recognized DNS challenge configuration, use the acme_dns global option at the top of your Caddyfile:

{
    acme_dns <provider> ...
}

For example:

{
    acme_dns cloudflare 1484053787dJQB8vP1q0yc5ZEBnH6JGS4d3mBmvIeMrnnxFi3WtJdF
}

Per-site configuration

Or, to enable the DNS challenge for a specific site only, use a tls directive in its site block:

tls {
    dns <provider> ...
}

for example:

tls {
    dns cloudflare 1484053787dJQB8vP1q0yc5ZEBnH6JGS4d3mBmvIeMrnnxFi3WtJdF
}

(You might also use a {env.*) placeholder if your credentials are in the environment.) Each provider may have a slightly different syntax; check module docs to be sure.

JSON

Or, if you use JSON, configure an automation policy with an acme issuer that sets the DNS challenge, for example:

{
	"module": "acme",
	"challenges": {
        "dns": {
            "provider": {
                "name": "cloudflare",
                "api_token": "YOUR_CLOUDFLARE_API_TOKEN"
            }
        }
    }
}
19 Likes
Caddy v2 Cloudflare plugin install
Anybody using wildcard SSL with Namecheap on Caddy?
How can I use DNS challenge in Caddy2?
Caddy version 1 end of life date
"The page isn’t redirecting properly" when runn
Rate limited by LetsEncrypt - how to resolve?
Configuring Caddy with Cloudflare DNS - The page isn’t redirecting properly
Error during parsing: getting module named 'dns.providers.cloudflare': module not registered: dns.providers.cloudflare, import chain: ['']
Unable to install Cloudflare DNS module
Can't obtain certificate on custom port http-01
Troubles with DNS-01 challenge using DuckDNS
Wildcard certificates, building from scratch and what Caddy is all about
Caddy2 Cloudflare-DNS Implimentation Windows Native
Caddy not requesting wildcard domain
Apple Pay TLS Cipher Suite Issues
How to get Cloudflare API token env variable?
Reverse Proxy Local Clients Directly to Local Server Using Same Domain as External Clients
Install a new module in Caddy 2
Enabling wildcard and on_demand certificates
Generic question about DNS providers & Caddy
Can't figure out how to get started w/ wildcard cert w/Route53 and Letsencrypt
Caddy in Docker On Private Network
Can I use netcup DNS acme challenge in docker?
Cannot get SSL/HTTPS certificate for my homelab
How would I setup Caddy with Cloudflare to hide my IP using Wildcard DNS records?
How to reuse certs generated by dns challenge?
On-demand Subdomains with HTTPS Failing
DNS-01 Challenge failing with Netcup DNS-Plugin
Rewrite current setup for automatic TLS on demand for new wildcard domain
Can't get certificates & DNS challenge refuses to work
Get an SSL certificate when ports 80 and 443 are unavailable on OpenVZ and X-UI panel
Is port forwarding necessary
Reverseproxy failes for local domain
Caddy issues with some sites but not others
Best practices for running an HTTPS reverse proxy behind a Wireguard tunnel
Newbe Configuring Caddy as Reverse Proxy
Changing nginx to caddy
PowerDNS plugin
Caddy as reverse proxy with duckdns package
Waiting for solver before continuing: Cant create a wildcard certificate
Caddy as "acme forward proxy"?
Serving tens of thousands of domains over HTTPS with Caddy
Caddy server SSL installed but not working
How to migrate from NGINX Ubuntu 20
Erorr With Dockerization On Unraid
Error obtaining certificate after Caddy restart
Caddy docker rootless problem with Certificate
Cannot connect to website https nor http
DNS domains for internal only with public ACME
Acme-dns support in caddy v2 as a dns provider
Caddy Docker with DuckDNS
SabNZBd Reserse Proxy V3.0.1 Docker - rss feeds
Tls interal still yields ERR_SSL_PROTOCOL_ERROR
DNS provider module in docker build 'not registered'
HTTPS in Backend, Caddy as Proxy ends in Errror 502
Could my Caddyfile be improved?
Change Port for port forwarding for reverse proxy?
Client TLS Setup (iOS, macOS)
Caddy2 integration is not starting (HassOS)
Help deploying Caddy with Cloudflare DNS
Help deploying Caddy with Cloudflare DNS
Caddy with UFW and autodrop of rules
Please explain auto tls failure
Enabling wildcard and on_demand certificates
Get ssl wildcard & conflict json file
How to install DNS provider plugins with Docker?
Cant get my DNS-Provider-Module for DNS-Challenge working
New DNS provider module
Unable to get wildcard certificate
Building caddy with dns provider module and docker getting caddy_build exited with code 0
Understanding module installation
Obtaining and renewing SSL/TLS certificates when Caddy sits behind an IP whitelist
Cannot start Caddy via Docker
How to get SSL without access to external ports 443/80?
Domain’s Supported
Caddy+Cloudflare on Docker SSL Error only on internal domain
Authorization failed on server
Referencing static files in HTML in handle_errors

A post was split to a new topic: How to get Cloudflare API token?

A post was split to a new topic: Advantages of libdns?

The global option is only in 2.4.0-beta.1, which should be pointed out.
Just spent 2 hours finding out that it wasn’t available on previous versions.

1 Like

That’s not exactly true, it existed for a long time before, but it was broken/non-functional until this commit: caddyfile: Refactor unmarshaling of module tokens · caddyserver/caddy@f021696 · GitHub

A post was split to a new topic: Split up ACME challenges

A post was split to a new topic: DNS challenge troubles

I am using 2.4.0-Beta.1 now. But even before that I was able to do the following

(cloudflare) {
      tls {
        dns cloudflare YOUR_API_KEY
      }
}
nas.myfancydomain.com {
      reverse_proxy http://192.168.1.51
      import cloudflare
}

It’s easier now that we can define it globally and not have to import it in every site configuration.

2 Likes

the doc link

seems outdate. (empty content)

maybe this link?

Fixed, thanks.

FYI, anyone can edit Wiki posts if you find a problem.

A post was split to a new topic: New DNS provider module

4 posts were split to a new topic: How to install DNS provider plugins with Docker?

6 posts were split to a new topic: How to use DNS provider plugins after building them