Error during parsing: getting module named 'dns.providers.cloudflare': module not registered: dns.providers.cloudflare, import chain: ['']

I’m just getting started with caddy as a reverse proxy and I’m having some problems. I’m starting from scratch.
LXC Debian 12 (internal IP 192.168.20.20)
Web server Debian 11 Apache2 (internal IP 192.168.20.11)
Install caddy

sudo apt install -y debian-keyring debian-archive-keyring apt-transport-https
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | sudo gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | sudo tee /etc/apt/sources.list.d/caddy-stable.list
sudo apt update
sudo apt install caddy

caddy version

v2.7.3

Ports open 443 and 80.
Config file is

/etc/caddy/Caddyfile
example.com {
    redir https://www{uri}
}

www.example.com {
    tls {
        dns cloudflare d8fc************************cb5f1057d
    }
    reverse_proxy 192.168.20.11:80
}

*.example.com {
    tls {
        dns cloudflare d8fc************************cb5f1057d
    }
    reverse_proxy 192.168.20.11:80
 }
cd /etc/caddy
caddy reload
2023/08/18 05:19:21.497	INFO	using adjacent Caddyfile
Error: adapting config using caddyfile: parsing caddyfile tokens for 'tls': Caddyfile:7 - Error during parsing: getting module named 'dns.providers.cloudflare': module not registered: dns.providers.cloudflare, import chain: ['']


See How to use DNS provider modules in Caddy 2. DNS plugins don’t come with Caddy out of the box.

1 Like

Well thank you
I know that cloudflare is an external plugin and the caddy developers have nothing to do with it. According to the information, I have to install xcaddy .

sudo apt install -y debian-keyring debian-archive-keyring apt-transport-https
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/xcaddy/gpg.key' | sudo gpg --dearmor -o /usr/share/keyrings/caddy-xcaddy-archive-keyring.gpg
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/xcaddy/debian.deb.txt' | sudo tee /etc/apt/sources.list.d/caddy-xcaddy.list
sudo apt update
sudo apt install xcaddy

I always end up with an error

/home/user/go/pkg/mod/github.com/quic-go/quic-go@v0.37.5/internal/qtls/go_oldversion.go:5:13: cannot use "The version of quic-go you're using can't be built using outdated Go versions. For more details, please see https://github.com/quic-go/quic-go/wiki/quic-go-and-Go-versions." (untyped string constant "The version of quic-go you're using can't be built using outdated Go...) as int value in variable declaration
note: module requires Go 1.20
2023/08/18 18:39:41 [INFO] Cleaning up temporary folder: /tmp/buildenv_2023-08-18-1839.1396406546
2023/08/18 18:39:41 [FATAL] exit status 2

Make sure you have at least Go 1.20 installed.

1 Like

I found a simple guide.

wget https://go.dev/dl/go1.21.0.linux-amd64.tar.gz
sudo tar -C /usr/local -xzf go1.21.0.linux-amd64.tar.gz
export PATH=$PATH:/usr/local/go/bin
go version
go version go1.21.0 linux/amd64

According to the previously sent instructions, I also created systemd scripts and run caddy as a systemd service. Everything seems to be working fine including the wildcard certificates.
However, I have a few questions.

For now, I’m testing caddy as a reverse proxy for one domain.
Question no. 1
My caddyfile looks like this

example.com {
    redir https://www.example.com{uri}
}

www.example.com {
    tls {
        dns cloudflare ***************************************************
    }
    reverse_proxy 192.168.20.11:80
}

*.example.com {
    tls {
        dns cloudflare ***************************************************
    }
    reverse_proxy 192.168.20.11:80
}

I want to implement hhtp headers in the configuration as well, and I found out that I have to do it in every block.

example.com {
    redir https://www.example.com{uri}
header /* {
    Strict-Transport-Security "max-age=31536000; includeSubDomains; preload"
    X-Xss-Protection "1; mode=block"
    X-Content-Type-Options "nosniff"
    X-Frame-Options "DENY"
    Content-Security-Policy "upgrade-insecure-requests"
    Referrer-Policy "strict-origin-when-cross-origin"
    Cache-Control "public, max-age=15, must-revalidate"
    Feature-Policy "accelerometer 'none'; ambient-light-sensor 'none'; autoplay 'self'; camera 'none'; encrypted-media 'none'; fullscreen 'self'; geo>
    Server "No."
}
}

www.example.com {
    tls {
        dns cloudflare ***************************************************
    }
    reverse_proxy 192.168.20.11:80
header /* {
    Strict-Transport-Security "max-age=31536000; includeSubDomains; preload"
    X-Xss-Protection "1; mode=block"
    X-Content-Type-Options "nosniff"
    X-Frame-Options "DENY"
    Content-Security-Policy "upgrade-insecure-requests"
    Referrer-Policy "strict-origin-when-cross-origin"
    Cache-Control "public, max-age=15, must-revalidate"
    Feature-Policy "accelerometer 'none'; ambient-light-sensor 'none'; autoplay 'self'; camera 'none'; encrypted-media 'none'; fullscreen 'self'; geo>
    Server "No."
}
}

*.example.com {
    tls {
        dns cloudflare ***************************************************
    }
    reverse_proxy 192.168.20.11:80
header /* {
    Strict-Transport-Security "max-age=31536000; includeSubDomains; preload"
    X-Xss-Protection "1; mode=block"
    X-Content-Type-Options "nosniff"
    X-Frame-Options "DENY"
    Content-Security-Policy "upgrade-insecure-requests"
    Referrer-Policy "strict-origin-when-cross-origin"
    Cache-Control "public, max-age=15, must-revalidate"
    Feature-Policy "accelerometer 'none'; ambient-light-sensor 'none'; autoplay 'self'; camera 'none'; encrypted-media 'none'; fullscreen 'self'; geo>
    Server "No."
}
}

Is it possible to do it globally?

Question no. 2
I will add more domains to caddyfile. Do I always have to use 1 caddyfile, or can I place domains in multiple config files?
In nginx, I had a separate configfile for each domain.

Question no. 3
If I want to update the caddy, is it enough to run this command?

xcaddy build --with github.com/caddy-dns/cloudflare

Question no. 4
How do I proceed if I want to build a caddy with more modules?
Edit: solved

Thank you very much

Use snippets: Caddyfile Concepts — Caddy Documentation

You can import from other files: import (Caddyfile directive) — Caddy Documentation, you always need a primary one which loads the rest.

Probably. You can specify the version of Caddy as the first argument after build, e.g. xcaddy build v2.7.4 --with ... if you want to build with a specific version. See the xcaddy README.

Also you need to copy the new binary to where it needs to go and restart the process.

Yeah, just do more --with.

1 Like

Thank you very much, I will try
:+1:

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