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.
Frequently when I see this behaviour, it’s because:
The client is connecting to Caddy over HTTPS
Caddy is connecting to the backend server over plain HTTP
The backend server wants Caddy to connect over HTTPS and issues a redirect
Caddy faithfully proxies the redirect back to the client
The client follows the redirect… to HTTPS, the same protocol it was already on
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.
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).