Trying to use Caddy behind Cloudflare (with caddy plugin), Caddy itself starts fine and listens on ports 443 and 80, but trying to load my-site-name.net fails on all browsers with error ERR_TOO_MANY_REDIRECTS.
My /etc/caddy/Caddyfile:
my-site-name.net
root /var/www/
tls {
dns cloudflare
}
My /etc/systemd/system/caddy.service.d/override.conf:
When attempting to load the website with lynx (in case this is useful):
$ lynx https://my-site-name.net
(â was prompted to accept cookie, selected Always)
Looking up my-site-name.net
Making HTTPS connection to my-site-name.net
Verified connection to my-site-name.net (subj=my-site-name.net)
Certificate issued by: /C=GB/ST=Greater Manchester/L=Salford/O=COMODO CA Limited/CN=COMODO ECC Domain Validation Secure Server CA 2
Secure 128-bit TLS1.2 (ECDHE_ECDSA_AES_128_GCM_SHA256) HTTP connection
Sending HTTP request.
HTTP request sent; waiting for response.
HTTP/1.1 301 Moved Permanently
'A'lways allowing from domain '.my-site-name.net'.
Data transfer complete
HTTP/1.1 301 Moved Permanently
lynx: Start file could not be found or is not text/html or text/plain
Exiting...
As far as Iâm aware Iâm not trying to do anything spectacularly complex. I tried setting CLOUDFLARE_API_KEY to the key listed on cloudflare as âOrigin CA Keyâ but this prevented Caddy from running at all.
I also tried making a single label for my-site-name.net and nesting the rootdir and tls directives within in, but it made no difference.
Try using log stdout or log syslog in your caddyfile to see which requests actually hit Caddy, and arenât just being redirected by Cloudflare for some reason.
Yeah, this doesnât belong in the Caddy documentation, because it is a Cloudflare issue. Itâs just one of the risks of adding this layer of complexity to your setup. Fortunately itâs an easy fix.