Getting ERR_TOO_MANY_REDIRECTS with forward_auth

I’m using the latest build of Caddy (v2.7.6) and I’m trying to use forward_auth directive to use an external source for authentication.

My external source of authentication (available at 127.0.0.1:5260), has two routes:

auth.example.com/verify ->for checking the authentication
auth.example.com/login ->for providing a login form

there’s also another route (test.example.com) that I’m trying to protect.

Caddyfile:

auth.example.com {
    reverse_proxy 127.0.0.1:5260
}

test.example.com {
    forward_auth auth.example.com {
      uri /verify
    }
    reverse_proxy 127.0.0.1:8080
}

Vising auth.example.com/verify from an unauthorized source, redirects to auth.example.com/login without any issue but when I visit test.example.com, I’m getting redirected to test.example.com/verify and browser shows ERR_TOO_MANY_REDIRECTS

That’s because you’re proxying on port 80 (default) which routes to Caddy itself, which triggers an HTTP->HTTPS redirect.

You should instead proxy directly to your auth server’s IP+port.

auth.example.com {
    reverse_proxy 127.0.0.1:5260
}

test.example.com {
    forward_auth 127.0.0.1:5260 {
      uri /verify
    }
    reverse_proxy 127.0.0.1:8080
}

Totally fixed that!. Thanks

1 Like

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