V2: too many redirects issue

1. Caddy version (caddy version):

local build from commit 3af15c0725605162dc8dad0c6ab241e2dc4553c6

2. How I run Caddy:

a. System environment:

alpine 3.12.0 docker container

b. Command:

./caddy run --config Caddyfile

c. Service/unit/compose file:

FROM alpine:3.12.0

ENV CADDYPATH=/etc/.caddy

WORKDIR /app
COPY . .

RUN apk add nss-tools

EXPOSE 80 443
CMD ["sh", "./run.sh"]

d. My complete Caddyfile or JSON config:

:443
tls internal

encode gzip
log
file_server
rewrite / /AMAG.Auth
reverse_proxy /AMAG.Auth* http://host.docker.internal:7325
reverse_proxy /AMAG.Portal* http://host.docker.internal:7326

3. The problem I’m having:

When I try to access the site I get a “too many redirects” browser error. Using the dev tools, I can see I’m generating an infinite loop of 308 redirects to my URL – https://dev.1fsilo.com redirects to https://dev.1fsilo.com, etc. Please note this URL is on an intranet and won’t be reachable for anyone outside our company.

4. Error messages and/or full log output:

No error messages in caddy logs. Firefox gives something like this:

“Firefox has detected that the server is redirecting the request for this address in a way that will never complete.”

Chrome gives something similar.

5. What I already tried:

  1. Specified the site name in Caddyfile
  2. Used wildcard on port 443 (as in above Caddyfile)
  3. Added reverse_proxy directive to localhost:443
  4. Tried to figure out how to eliminate the “rewrite” directive in above Caddyfile thinking that may be the culprit. I don’t see a way to do this, though, as I need “/” to redirect to “AMAG.Auth”. I can just reverse_proxy / http://host.docker.internal:7325 to pull up the index.html file, but then I get 404s on all my requests for css, images, and js – those requests need to be forwarded to “AMAG.Auth” as well.

6. Links to relevant resources:

7. Additional comments:

There’s a load balancer or proxy in front of Caddy in this case, and ordinarily I’d blame that but this worked with Caddy 0.x so that can’t be the whole story. I guess I’m wondering what’s different between Caddy 0.x and Caddy 2 that might cause this kind of redirect loop? Is this plausibly being caused by the rewrite directive or does it seem like the issue might be upstream of that?

Not sure how much help anyone can give me given the lack of information I have about the proxy we have in front of Caddy, but any help at all is greatly appreciated.

Edit: I just saw another “Too many redirects” post from Dec. that I hadn’t been able to find searching, looking at that now.

1 Like

Sorry, this was my mistake. TLS is terminated at the load balancer so the problem is really that I just need to disable TLS.

2 Likes

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