Getting ERR_TOO_MANY_REDIRECTS with Cloudflare tunnel + Caddy

1. The problem I’m having:

I’m simply trying to see if Caddy is working or not. I added a respond directive just to make sure I can reach my system. But I’m getting The page isn’t redirecting properly errors.

2. Error messages and/or full log output:

{"level":"info","ts":1694382120.2321503,"msg":"using provided configuration","config_file":"/etc/caddy/Caddyfile","config_adapter":"caddyfile"}
{"level":"info","ts":1694382120.2348268,"logger":"admin","msg":"admin endpoint started","address":"localhost:2019","enforce_origin":false,"origins":["//localhost:2019","//[::1]:2019","//127.0.0.1:2019"]}
{"level":"info","ts":1694382120.2350545,"logger":"tls.cache.maintenance","msg":"started background certificate maintenance","cache":"0xc000328800"}
{"level":"info","ts":1694382120.2350945,"logger":"http.auto_https","msg":"server is listening only on the HTTPS port but has no TLS connection policies; adding one to enable TLS","server_name":"srv0","https_port":443}
{"level":"info","ts":1694382120.2351086,"logger":"http.auto_https","msg":"enabling automatic HTTP->HTTPS redirects","server_name":"srv0"}
{"level":"info","ts":1694382120.2352796,"logger":"tls","msg":"cleaning storage unit","description":"FileStorage:/data/caddy"}
{"level":"info","ts":1694382120.2353582,"logger":"http","msg":"enabling HTTP/3 listener","addr":":443"}
{"level":"info","ts":1694382120.2356315,"msg":"failed to sufficiently increase receive buffer size (was: 208 kiB, wanted: 2048 kiB, got: 416 kiB). See https://github.com/quic-go/quic-go/wiki/UDP-Buffer-Sizes for details."}
{"level":"info","ts":1694382120.2358627,"logger":"http.log","msg":"server running","name":"srv0","protocols":["h1","h2","h3"]}
{"level":"info","ts":1694382120.23593,"logger":"tls","msg":"finished cleaning storage units"}
{"level":"info","ts":1694382120.2359698,"logger":"http.log","msg":"server running","name":"remaining_auto_https_redirects","protocols":["h1","h2","h3"]}
{"level":"info","ts":1694382120.2359867,"logger":"http","msg":"enabling automatic TLS certificate management","domains":["links.sintan1729.uk"]}
{"level":"info","ts":1694382120.2367013,"msg":"autosaved config (load with --resume flag)","file":"/config/caddy/autosave.json"}
{"level":"info","ts":1694382120.23671,"msg":"serving initial configuration"}

3. Caddy version:

v2.7.4 h1:J8nisjdOxnYHXlorUKXY75Gr6iBfudfoGhrJ8t7/flI=

4. How I installed and ran Caddy:

a. System environment:

Running inside a Docker on AlmaLinux 9.2

b. Command:

docker compose up -d

c. Service/unit/compose file:

services:
  caddy-cloudflare:
    image: 'iarekylew00t/caddy-cloudflare:latest'
    container_name: caddy
    restart: always
    ports:
      - '80:80'
      - '443:443'
    volumes:
      - './caddy_data:/data'
      - './caddy_config:/config'
      - './Caddyfile:/etc/caddy/Caddyfile'
    networks:
      - proxy_network

networks:
  proxy_network:
    external: true

d. My complete Caddy config:

{
        acme_dns cloudflare <REDACTED>
}

links.sntn1729.uk {
        respond "Hi!"
}

To add some more context, I’m exposing Caddy to the internet over Cloudflare tunnel. I do have the security mode set to Full (Strict). It works with Nginx Proxy Manager, so I don’t think there’s any issue in my setup outside of Caddy.

Never mind, I solved it. cloudflared was forwarding to localhost:80. Had to change it to https://localhost:443 and set the Origin Server Name to the domain name.

2 Likes

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