Caddy: Too Many Redirects

1. My Caddy version (caddy version):

Caddy v1.0.1-0.20190527141219-14a8ffedd8d4

2. How I run Caddy:

caddy.service:

[Unit]
Description=Caddy HTTP/2 web server
Documentation=https://caddyserver.com/docs
After=network-online.target
Wants=network-online.target systemd-networkd-wait-online.service

[Service]
Restart=on-abnormal

User=root
Group=root

ExecStart=/usr/local/bin/caddy -agree -email email@redacted.com -http2 -log /opt/caddy/log -root /opt/caddy/webroot -conf /opt/caddy/Caddyfile
Environment="CLOUDFLARE_EMAIL=emailredacted"
Environment="CLOUDFLARE_API_KEY=keyredacted"
ExecReload=/bin/kill -USR1 $MAINPID

KillMode=mixed
KillSignal=SIGQUIT
TimeoutStopSec=5s

LimitNOFILE=1048576
LimitNPROC=64

CapabilityBoundingSet=CAP_NET_BIND_SERVICE
AmbientCapabilities=CAP_NET_BIND_SERVICE
NoNewPrivileges=true

[Install]
WantedBy=multi-user.target

a. System environment:

Caddy is non-docker.
OS: Debian 9 64 Bit

b. Command:

NA

c. Service/unit/compose file:

Wordpress Configuration

version: '3.3'

services:
  db:
    image: mysql:5.7
    container_name: site-db
    volumes:
      - /srv/dev-disk-by-label-xdata/docker/site/db:/var/lib/mysql
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: password1
      MYSQL_DATABASE: wpdb
      MYSQL_USER: wordpress
      MYSQL_PASSWORD: password
    networks:
      caddynet:
        ipv4_address: 172.30.1.29

  wordpress:
    depends_on:
      - db
    container_name: site-wp
    image: wordpress:latest
    ports:
      - "8409:80"
    restart: always
    environment:
      WORDPRESS_DB_HOST: db:3306
      WORDPRESS_DB_USER: wordpress
      WORDPRESS_DB_PASSWORD: password
      WORDPRESS_DB_NAME: wpdb
    networks:
      caddynet:
        ipv4_address: 172.30.1.28

networks:
  caddynet:
    external:
      name: caddynet

d. My complete Caddyfile or JSON config:

www.mydomain.com {
  root /gvault/webserver/site
}

test.mydomain.com {
  proxy / 172.30.1.28:80 {
    transparent
    websocket
  }
  tls {
    dns cloudflare
  }
}

3. The problem I’m having:

When trying to navigate to test.mydomain.com, I get “Too many redirects”.

4. Error messages and/or full log output:

2020/02/18 14:04:23 [INFO] Serving http://test.mydomain.com
2020/02/18 14:04:55 [ERROR] failed to copy buffer:  read tcp 192.168.2.3:443->xx.9.41.xx:10956: use of closed network connection
2020/02/18 14:05:00 http: TLS handshake error from xx.63.162.xx:60225: no certificate available for 'mydomain.com'
2020/02/18 14:05:00 http: TLS handshake error from xx.63.162.xx:61697: no certificate available for 'mydomain.com'
2020/02/18 14:05:01 http: TLS handshake error from xx.63.162.xx:56673: read tcp 192.168.2.3:443->93.63.162.100:56673: read: connection reset by peer
2020/02/18 14:05:47 http: TLS handshake error from 192.168.2.1:56666: EOF

5. What I already tried:

Cloudflare TLS is set to strict.
www subdomain works fine.
Navigating to the local IP address works just fine. The Wordpress container comes right up.

6. Links to relevant resources:

Hi @jiru443,

If Wordpress is fine locally via IP address, it’s probably expecting HTTP. Is Wordpress issuing a canonical/downgrade redirect based on the transparent preset’s X-Forwarded-Proto header?

You can try taking Wordpress out of the equation temporarily by serving a site with status 200 /. If that works, we know it’s a Wordpress issue.

You could also try taking Cloudflare’s reverse proxy off the table temporarily if it’s not a Wordpress issue.

P.S.: redacted.com and mydomain.com are both registered domains serving existing websites. We prefer you don’t redact anything - but if you must, instead of using someone else’s domain name, use the one that’s IANA-reserved specifically for this purpose: example.com.

In Caddy v1, the transparent preset the OP has in their configuration does those headers (and two others):

https://caddyserver.com/v1/docs/proxy#presets

1 Like

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