Trusted Proxies with Cloudflare - my solution

being new to caddy the response didn’t quite have enough detail for me to get it working.

So for other newbies, I had to place it in the global section at the top of my Caddyfile.

I also had to to a custom build of caddy to include the trusted proxies cloudflare module. I’ve included my docker file as well.

{
	# Email for Let's Encrypt notifications
	email {$EMAIL}
	# ACME CA URL allows us to flip between production and staging.
	# we default to staging.
	acme_ca ${ACME_URL:https://acme-staging-v02.api.letsencrypt.org/directory}

	log {
		output file /var/log/caddy/all.log
	}

	# trigger the cloudflare ip module that periodically fetches
    # the list of valid cloud flare proxy IP addresses.
	servers {
		trusted_proxies cloudflare {
			interval 12h
			timeout 15s
		}
	}
}
# we build our own caddy file as we need the cloudflare module.
FROM caddy:2.9.1-builder AS builder

# https://caddyserver.com/docs/modules/dns.providers.cloudflare
RUN xcaddy build \
    --with github.com/caddy-dns/cloudflare \
    --with github.com/WeidiDeng/caddy-cloudflare-ip

FROM caddy:2.9.1

COPY --from=builder /usr/bin/caddy /usr/bin/caddy

COPY config/caddy /etc/caddy

# CMD ["tail", "-f", "/dev/null"]

CMD ["caddy", "run", "--config", "/etc/caddy/Caddyfile", "--adapter", "caddyfile"]