Too many redirects occurred trying to open site

I can use http://ip:port to visit my site, but when I use the domain, it will tells me wrong with error information like this

Too many redirects occurred trying to open “https://domain.com”. This might occur if you open a page that is redirected to open another page which then is redirected to open the original page.

My Caddyfile is following

domain.com {
 tls hbdfdjkl@gmail.com
 proxy / ip:port {
    header_upstream Host {host}
    header_upstream X-Real-IP {remote}
    header_upstream X-Forwarded-For {remote}
    header_upstream X-Forwarded-Proto {scheme}
  }
 log /var/log/caddy.log
 gzip
}

And I change proxy / ip:port to proxy / http://ip:port, both of them can’t work.

Any ideas?

Hi @hzb, welcome to the Caddy community.

Frequently when I see this behaviour, it’s because:

  1. The client is connecting to Caddy over HTTPS
  2. Caddy is connecting to the backend server over plain HTTP
  3. The backend server wants Caddy to connect over HTTPS and issues a redirect
  4. Caddy faithfully proxies the redirect back to the client
  5. The client follows the redirect… to HTTPS, the same protocol it was already on
  6. Repeat ad infinitum

Certainly there are no redirects in your Caddyfile that would loop like this. Ensure your upstream server is not sending these redirects mistakenly - this might involve having Caddy proxy it over HTTPS, or maybe changing a setting on the backend application itself.

1 Like

@Whitestrake Thank you for the reply, and I am first time to use Caddy. Let me make it clear.

First, my Caddyfile is following, no anything else.

domain.com {
 tls hbdfdjkl@gmail.com
 proxy / ip:port {
    header_upstream Host {host}
    header_upstream X-Real-IP {remote}
    header_upstream X-Forwarded-For {remote}
    header_upstream X-Forwarded-Proto {scheme}
  }
 log /var/log/caddy.log
 gzip
}

Second, it worked well before I changed the port. I used 80 port as the backend application port, and the Caddyfile is like this

domain.com {
 tls hbdfdjkl@gmail.com
 proxy / ip {
    header_upstream Host {host}
    header_upstream X-Real-IP {remote}
    header_upstream X-Forwarded-For {remote}
    header_upstream X-Forwarded-Proto {scheme}
  }
 log /var/log/caddy.log
 gzip
}

Everything works well, and I only changed the backend application’s port, caddy can’t work. So, I do n’t quite understand the explanation in your reply, thank you.

Caddy isn’t issuing any redirects. For some reason, your application is issuing redirects when you have Caddy proxy to it on a specific port instead of port 80.

You need to fix that so that your application accepts requests on the specified port without redirecting Caddy (and hence the client).

@Whitestrake I see, thank you so much.

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