title: How to properly setup Keycloak redirects behind reverse proxy with SpringSecurity
body: <p>I have a Spring based application, which uses <code>keycloak-spring-security-adapter</code> to handle the Keycloak specific stuff. This server is deployed on same machine as the Keycloak server, and both of them are running behind Nginx reverse proxy.</p>
  <p><a href="https://i.stack.imgur.com/O3Z2D.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/O3Z2D.png" alt="network connection diagram" /></a></p>
  <p>The Spring app has in its <code>keycloak.json</code> configuration the correct proxy-url. The Keycloak server has the the <code>frontendUrl</code> set to the correct proxy-url. When testing on localhost without the reverse proxy everything works as expected.</p>
  <p>The issue is when deployed with the reverse-proxy in front. The Spring application runs the OIDC service discovery during startup. But to do this, is uses the public URL. This fails, because the on the backend side, the reverse proxy is not in DNS record.</p>
  <p>How to setup the <code>keycloak-spring-security-adapter</code> in such a way, that for the backend requests it uses local URL. But for the logins that are done through the JSP pages in the browser, it uses the proxied URL?</p>