Keycloak Ops
Isometric magenta cube with a pink keyhole symbol, connected across a dotted grid to three glowing pink cylinders on a dark purple background.
troubleshooting

Keycloak Behind a Reverse Proxy: Fix 403 and Hostname Errors

Fix Keycloak hostname errors behind a reverse proxy, from 403 responses and incorrect issuers to rejected redirect URIs and admin console path issues.

By Keycloak Ops Editorial · ·Updated · 4 min read

Set hostname to Keycloak’s full public HTTPS URL to fix incorrect issuers and discovery URLs behind a reverse proxy. If the proxy terminates TLS, set proxy-headers to match the headers it sends so Keycloak can determine the request origin. Keycloak hostname guide, Keycloak reverse proxy guide.

Symptom: 403 Forbidden on Requests Through the Proxy

When the proxy terminates TLS and proxy-headers is unset, Keycloak returns 403 Forbidden by default on proxied requests that perform origin checks. Have the proxy overwrite the relevant incoming headers with its own values, then configure Keycloak to read that header format. Reverse proxy guide.

Headers set by the proxy Keycloak startup option
Forwarded --proxy-headers forwarded
X-Forwarded-* --proxy-headers xforwarded

For a fixed public URL and a proxy that sets X-Forwarded-*, the hostname guide gives this startup example. Substitute your public URL and keep your existing database and TLS settings. Hostname guide.

bin/kc.sh start --hostname https://my.keycloak.org --proxy-headers xforwarded

For edge termination with an HTTP connection from the proxy to Keycloak, also set --http-enabled=true. With TLS re-encryption, the proxy connects to Keycloak over HTTPS. With TLS passthrough, leave proxy-headers unset because the proxy cannot overwrite headers inside the encrypted request. Reverse proxy guide.

Set proxy-trusted-addresses to a comma-separated list of your proxy IPs or CIDR ranges. Keycloak accepts forwarding headers from any source by default. With this list set, it ignores forwarding headers from addresses outside the list. Reverse proxy guide.

A full hostname URL fixes the public scheme, host, port and context path. A bare hostname still leaves the scheme, port and path to be resolved dynamically. When hostname is configured, Keycloak ignores hostname-strict. The latter defaults to true in production and must be set to false when running in production without hostname. Hostname guide, configuration reference.

A full URL still leaves forwarding headers in use for origin checks when proxy-headers is enabled. By default, backchannel URLs use the frontend address. Deployments intentionally serving clients over a private network can set hostname-backchannel-dynamic=true with a full hostname URL. With TLS passthrough, a certificate for the public hostname can fail validation on a private backchannel hostname. Hostname guide.

To inspect URL resolution, temporarily set --hostname-debug=true and open /realms/master/hostname-debug under the Keycloak base URL. Disable the debug page after checking it. Configuration reference.

Symptom: Invalid Parameter, redirect_uri

If Keycloak shows Invalid parameter: redirect_uri during authorization, compare the redirect_uri sent by the application with the registered callbacks for that OIDC client. Authorization request checks, English login messages.

In the Admin Console, open Clients, select the client, and open Settings. Under Access Settings, update Valid Redirect URIs with the application’s intended callback URL and click Save. For exact entries, Keycloak compares strings case-sensitively. Avoid the unrestricted * entry in production. Server Administration Guide.

For example, if the registered URI is https://app.example.com/callback, compare the actual request for a different scheme or port, a trailing slash, or an added query string. Each changes the string compared against that exact entry. Server Administration Guide.

Symptom: HTTPS Required

During authorization, Keycloak can show “HTTPS required” when the resolved scheme is HTTP and the realm requires HTTPS for the connection. The realm control is Realm settings → General → Require SSL. Authorization HTTPS check, English login messages, Server Administration Guide.

If the browser already uses HTTPS and the proxy terminates TLS, check proxy-headers and the scheme the proxy forwards. With xforwarded, check that X-Forwarded-Proto reflects the browser’s HTTPS connection. Keep the realm’s HTTPS policy in place while correcting the proxy. Reverse proxy guide, production guide.

Symptom: Admin Console Loads Blank or Loops

Check the public path. If the proxy exposes Keycloak under /auth but forwards to Keycloak at /, include /auth in the public URL with --hostname=https://my.keycloak.org/auth. Another documented option uses a bare hostname, --proxy-headers xforwarded and a proxy that sets X-Forwarded-Prefix. To serve the same context path on both sides, set http-relative-path to that path. Reverse proxy guide.

Check the admin address. If you serve the console on a separate address, set hostname-admin to its full URL. Set hostname to a full frontend URL as well, as required by startup validation. The console uses the admin URL for redirects, static resources and Admin REST API calls. The documented example pairs --hostname https://my.keycloak.org with --hostname-admin https://admin.my.keycloak.org:8443. Hostname guide.

An Ordered Checklist

  1. Confirm TLS mode and proxy trust. Match proxy-headers to the header format for edge termination or re-encryption, and set proxy-trusted-addresses. For edge termination over an HTTP upstream, enable http-enabled. For passthrough, leave proxy-headers unset. Reverse proxy guide.
  2. Set the public URL. Configure a full hostname, including any public path prefix. Keycloak uses that URL and ignores hostname-strict. Check hostname-admin if the console has its own URL. Hostname guide, reverse proxy guide.
  3. Verify the public discovery document. Open https://my.keycloak.org/realms/example/.well-known/openid-configuration with your public base URL and realm name substituted. Check the issuer, authorization_endpoint and token_endpoint against the addresses your client should use. The issuer must match the ID token’s iss claim. Hostname guide, OpenID Connect Discovery specification.
  4. Check the application callback. If the discovery URLs are correct and the login still reports a redirect URI error, compare the application’s requested callback with Valid Redirect URIs on its client in Keycloak. Server Administration Guide.

For background on the client and realm settings, see Keycloak realms, clients and token design fundamentals.

For deployment sizing, see Keycloak hardware requirements and heap sizing and the sizing calculator. Keycloak vs authentik vs Authelia compares the alternatives on architecture and footprint.

Evidence and limits. The configuration guidance follows the Keycloak hostname v2 and reverse proxy documentation. The client and realm settings and login messages were checked against the Keycloak 26.6.4 administration guide and source code. The steps were not run in a deployment.

Sources

  1. Keycloak — Configuring the hostname (v2)
  2. Keycloak — Configuring a reverse proxy
  3. Keycloak — All configuration options
  4. Keycloak — Configuring Keycloak for production
  5. Keycloak — Server Administration Guide 26.6.4
  6. Keycloak 26.6.4 — OIDC authorization request checks
  7. Keycloak 26.6.4 — Authorization HTTPS check
  8. Keycloak 26.6.4 — English login messages
  9. OpenID Foundation — OpenID Connect Discovery 1.0

Related