Why Keycloak needs a reverse proxy setup with NGINX, HAProxy or Traefik
A team that puts Keycloak behind a load balancer or ingress often discovers the problem on the first login. Redirects point to an internal address, the browser blocks scripts or forms because a page loads over HTTP inside an HTTPS login, or the admin console is reachable from the public internet. The proxy is where these URLs, certificates and paths are either set correctly or left to chance. Keycloak needs to know the public scheme, host and port that clients actually used, and the proxy is the component that sees them first.
The Keycloak production guide asks for TLS on all communication, a reverse proxy that restricts paths, and a split between the hostname that serves the admin console and Administration REST API and the hostname used for public frontend URLs. Those three requirements shape the rest of the build. The proxy has to terminate or pass through TLS, forward the headers Keycloak uses to rebuild its URLs, and refuse requests to admin paths on the public name. A proxy that only forwards traffic leaves all three open.
Before you choose NGINX, HAProxy or Traefik, confirm three things in your environment: which hostnames users, applications and administrators will each use, whether the proxy will re-encrypt traffic to Keycloak or pass it through, and whether any client must present an X.509 certificate that the proxy has to forward. Each answer changes the proxy configuration and the Keycloak hostname settings. Check the exact header and hostname options against the Keycloak documentation for your release, because the server configuration changes between versions.
Which proxy option fits which Keycloak setup
This table compares the proxy design choices that matter for Keycloak: TLS re-encrypt versus passthrough, PROXY protocol, and how NGINX, HAProxy and Traefik handle forwarded headers and path routing. Read each row against your client certificate, hostname and admin exposure requirements, then confirm every product-specific directive in the vendor documentation before you build.
| Decision or setup | Recommended design | Trade-off | Confirm before building |
|---|---|---|---|
| Standard browser and app sign-in, no X.509 login | TLS re-encrypt: proxy terminates the public certificate and opens a new TLS connection to Keycloak | Proxy sees plaintext, so it can enforce path rules and headers, but it must trust the internal certificate | Proxy trust store entry for the Keycloak certificate and the hostname it presents |
| X.509 client certificate login | TLS passthrough, or re-encrypt with the client certificate forwarded in a header that Keycloak trusts | Passthrough keeps the client certificate intact but limits path inspection. Header forwarding moves trust to the proxy | How Keycloak is told to read the forwarded certificate header, and which proxy addresses it accepts |
| Path blocking for the admin console and Administration REST API | Terminate or re-encrypt at the proxy and deny admin paths on the public hostname | Requires path rules that match Keycloak's current paths, which change between releases | Exact admin and management paths for your release, and whether a separate admin hostname is in use |
| Client IP preservation for logs, rate limits and brokering | Forwarded headers from trusted proxy addresses only, or PROXY protocol where the load balancer supports it | Trusting headers from untrusted sources lets clients spoof their address | Keycloak proxy settings for trusted addresses, and whether the load balancer sends PROXY protocol headers |
| PROXY protocol on the front load balancer | Enable PROXY protocol on the listener and the matching Keycloak ingress, on both sides of the hop | A mismatch on either side breaks every connection, and the failure can look like a TLS error | Listener and backend settings in the NGINX, HAProxy or Traefik directive reference for your version |
| NGINX in front of Keycloak | Strong fit for re-encrypt with explicit location blocks for public and admin paths | Forwarded header handling is set in configuration you write and maintain yourself | Directive names for upstream TLS, client certificate passing and forwarded headers in the NGINX docs |
| HAProxy in front of Keycloak | Strong fit for passthrough and PROXY protocol on high-volume front ends | Path restrictions and header rewriting need ACLs that are more verbose to test | ACL, SSL passthrough and PROXY protocol settings in the HAProxy docs for your build |
| Traefik in front of Keycloak | Fits container and Kubernetes ingress where routes are generated from labels or resources | Route and middleware behavior depends on the provider in use, so changes need review | Middleware for forwarded headers, TLS options and passthrough routes in the Traefik docs for your provider |
| Keycloak hostname and proxy settings | Set the public hostname and proxy mode in Keycloak to match what clients see | A wrong hostname causes redirect and token issuer errors that look like login failures | Hostname and proxy configuration keys for your Keycloak release in the production guide |
A login request passes the proxy before Keycloak trusts its headers
The diagram starts at the browser, which sends the login to the public hostname. The reverse proxy terminates or re-encrypts TLS and adds forwarded headers, and Keycloak accepts those headers only from proxy addresses it trusts. The admin console and Administration REST API sit on a separate hostname or context path that the proxy restricts, so public traffic never reaches them. Check that the trust boundary matches your proxy addresses and that admin paths are blocked on the public side.
Login traffic from the browser through the proxy to Keycloak, with the trust boundary marked.
Set up the proxy in front of Keycloak step by step
This sequence takes a Keycloak node from direct exposure to a reverse proxy that terminates TLS, forwards the correct public identity, exposes only the paths users need, and keeps the admin surface on its own hostname. Each step ends with a check you can run before moving on.
Confirm the public hostname and URL layout
The platform or security owner decides the public hostname users will see, such as sso.example.com (illustrative), and whether the admin console and Administration REST API will live on a separate hostname or context path. Write these values down before touching any configuration, because Keycloak builds its issuer and endpoint URLs from them. Done when the team has one agreed public hostname, one admin hostname or path, and the internal address of each Keycloak node that the proxy will reach.
Configure TLS termination or re-encryption on the proxy
The proxy team installs a certificate for the public hostname on NGINX, HAProxy or Traefik and chooses between terminating TLS at the proxy and re-encrypting to Keycloak over HTTPS. Keycloak's production guide calls for TLS on all communication, so re-encrypt unless your network design already protects the internal hop. Verify by connecting with openssl s_client or a browser to the public hostname and confirming the certificate chain is complete and valid for that name.
Set forwarded headers and trusted proxy addresses on Keycloak
The Keycloak administrator sets the hostname and proxy settings so Keycloak trusts the forwarded headers only from the proxy's internal addresses. Use the hostname and proxy options documented for your Keycloak version, and check the exact option names against the production configuration guide before deployment. Confirm the proxy sends X-Forwarded-For, X-Forwarded-Proto, X-Forwarded-Host and X-Forwarded-Port (or the Forwarded header) as your chosen configuration expects. Done when a request through the proxy shows Keycloak generating https URLs on the public hostname, not the internal address.
Verify the discovery document and issuer URL
Before exposing any application, the identity engineer requests the OpenID Connect discovery document for the realm through the public hostname. Check that the issuer value, authorization_endpoint, token_endpoint and jwks_uri all use the public https hostname and the correct realm path. Any internal hostname, plain http scheme or wrong port means the forwarded header settings or the hostname configuration need correction. Repeat this check after each change to the proxy or Keycloak configuration.
Expose only the public paths and block everything else
The proxy administrator creates allow rules for the paths end users and applications need, typically the realm's OpenID Connect and SAML endpoints, the login and account pages, and static resources the themes require. Deny by default and return a clear error for all other paths, including the admin console, the Administration REST API, and management endpoints such as /metrics. The paths you allow should be listed in the change record so auditors can compare them with the configuration later. Verify by requesting a blocked path from outside the internal network and confirming the proxy returns a denial, then requesting an allowed login path and confirming it loads.
Route the admin console and Administration REST API separately
The Keycloak administrator places the admin console and Administration REST API on a separate hostname or context path, with access restricted to administrator networks, and keeps the admin hostname distinct from the public frontend URL. Apply the same deny-by-default posture to the management interface so metrics and health endpoints are not reachable from public networks. Verify from an approved admin network that the console loads on the admin hostname, and from a public network that the same paths fail. Confirm also that the public discovery document still reports the public hostname, not the admin one.
Enable PROXY protocol or client certificate forwarding only if needed
Enable PROXY protocol on the load balancer and in Keycloak only when the upstream load balancer requires it to pass the original client address, and make sure both sides are configured together, since a mismatch breaks every connection. Forward client certificates to Keycloak only when the X.509 certificate login flow requires it, and restrict the forwarding header to the proxy's address so clients cannot spoof it. Confirm that the header names and certificate format match the Keycloak settings for your version. Verify with a test login using a client certificate from a known test user, and confirm the audit log records the expected client address.
Which paths to expose and which to block at the proxy
A Keycloak proxy config is mostly a list of path rules. Public authentication endpoints must stay reachable for applications and browsers, while the admin console, Administration REST API and metrics belong on separate hostnames, contexts or internal networks. Confirm the exact path list against the Keycloak version you run, because endpoint layout changes between releases.
Public authentication endpoints
Applications and browsers need the realm paths under /realms/ for OpenID Connect discovery, authorization, token, userinfo, logout and the login pages, plus the resources used by the login theme. Expose these on the public frontend hostname only. Check that your proxy forwards the full realm path without rewriting it, since clients validate the issuer URL against what Keycloak advertises in discovery.
Admin console and admin REST API
The admin console under /admin/ and the Administration REST API should not be reachable from the internet. The production guide recommends serving them on a different hostname or context path from public frontend URLs. At the proxy, block these paths on the public listener and allow them only from administrator networks, VPN ranges or a bastion, and confirm that the admin hostname is configured in Keycloak so generated links point to the right place.
Metrics on the management interface
Prometheus metrics are served at /metrics when Keycloak runs with --metrics-enabled=true, and they expose operational detail about your identity service. Keep this path off the public proxy entirely and let only your monitoring network scrape it, either directly on the management port or through an internal route. Confirm which management port your version uses before writing the deny rule, so the block does not depend on a path that is never reached.
Health endpoints for load balancers
Health check endpoints under /health support load balancer probes and orchestrator liveness and readiness checks. Decide whether your load balancer reaches them on the management interface, which is usually internal, or through the proxy. If they are exposed publicly, limit what they reveal, and do not let a health check rule accidentally open the admin paths next to it.
Proxy rules to test before go-live
Write allow and deny rules as explicit path matches with a default deny for anything unlisted. Test each rule from an outside network and from an admin network, and include paths with trailing slashes, encoded characters and double slashes, since proxies differ in how they normalize them. Keep a written list tied to the Keycloak version, and retest it on every upgrade because new endpoints can appear in a minor release.
Forwarding client certificates for X.509 login
X.509 client certificate login only works if the proxy hands the client certificate to Keycloak. When TLS ends at the proxy, the client's certificate is validated there and Keycloak receives a plain HTTP request, so the certificate never reaches the server unless the proxy copies it into a request header. Keycloak then reads that header and matches the certificate against its configured trust store and certificate-to-user mapping. Terminating TLS at the proxy gives you one place to manage certificates and lets the proxy enforce client authentication for every route, but it moves a security decision out of Keycloak and into header handling. Passing TLS through to Keycloak keeps the handshake and the certificate inside Keycloak, which avoids header trust entirely, but it is harder to combine with the proxy's path rules and HTTP-level controls.
The header name, its encoding and the trusted sources are version-specific, so confirm them in the Keycloak documentation for the release you run before you write the proxy configuration. The proxy must send the certificate in the format Keycloak expects, typically a URL-encoded PEM value, and Keycloak must be told which proxy addresses it may accept that header from. Check the current production and reverse proxy settings for the proxy-related and client-certificate options in your version, and test with a certificate that you control rather than assuming a sample configuration applies to your build.
The main risk is a spoofed certificate header. If Keycloak accepts the header from any client, an attacker can send a forged value and log in as another user. Your proxy must strip any incoming copy of the header from external requests before it sets its own, and the Keycloak listener must accept that header only from the proxy's trusted addresses. Run a negative test that sends the header directly from an untrusted host and confirm the login is refused. If TLS passthrough is chosen, the header path is not used at all, so remove any header-forwarding rules to keep the attack surface small.
Security and operational risks of a misconfigured proxy
A reverse proxy sits between every client and Keycloak, so its header handling, routing and certificates decide what Keycloak believes about the request. The cards below cover the security failures that follow from a loose proxy and the operational checks that keep a correct setup correct after the first deployment.
Spoofed forwarded headers
Keycloak builds issuer URLs, redirects and client IP records from forwarded headers when the proxy is configured to trust them. If the proxy passes through headers sent by the client instead of overwriting them, an attacker can set the host or address Keycloak sees. Check that the proxy sets X-Forwarded-For, X-Forwarded-Proto and X-Forwarded-Host itself and that Keycloak only accepts them from the proxy's own addresses.
Exposed admin endpoints
The admin console and Administration REST API should not be reachable through the public hostname. The production guide calls for a separate hostname or context path for admin traffic. Verify from outside your network that admin paths return an error and that the proxy blocks paths you do not intend to publish, including the management interface and its metrics path.
Weak TLS on the proxy segment
The proxy often terminates the browser connection with a strong configuration while the hop to Keycloak uses a weak or unencrypted one. Keycloak's production guide calls for TLS on all communication. Confirm the protocol versions and cipher suites on both listeners, and decide whether the internal hop uses re-encryption with certificate validation or passthrough, then test both sides with a scanner.
Redirect URIs built from the wrong host
When the hostname settings do not match what the proxy presents, Keycloak can issue issuer URLs or redirects that point at an internal address or the wrong port. Clients then fail token validation or send users to unreachable pages. Compare the issuer value in the discovery document with the public URL, and check that the redirect URIs registered for each client use the exact scheme, host and port the proxy exposes.
Logging of sensitive headers
Proxy access logs often capture full request headers, including Authorization, cookies and session identifiers. Those logs are usually copied to a central log platform with wider access than the identity system. Define a log format that omits credential and cookie headers, set retention for proxy logs, and confirm that Keycloak's own logging does not echo the same values.
Health and metrics routing checks
Load balancers and monitoring systems call Keycloak's health and metrics endpoints on the management interface. If the proxy routes these paths to the public listener, they are either unreachable for probes or exposed to the internet. Test that health checks succeed through the proxy, that the metrics path is reachable only from the monitoring network, and that metrics scraping does not depend on public routing.
- Metrics path
- /metrics
Questions teams ask before setting up a Keycloak reverse proxy
How much effort does a Keycloak reverse proxy setup usually take?
Effort depends less on the proxy product than on how many decisions are open: hostnames, TLS design, which paths are public, and whether client certificates reach Keycloak. A single-hostname setup with TLS terminated at the proxy is a small job. Adding a separate admin hostname, TLS re-encryption, PROXY protocol and X.509 login multiplies the testing, because each one changes how Keycloak reads client IP, scheme and certificate headers. The work is mostly configuration and verification, not new software. Ask any provider to break its quote into design, configuration, testing and handover so you can see where the hours go.
How long does a Keycloak reverse proxy project take?
No timeline is fixed in advance, because duration follows the drivers that change the design. The main ones are the number of public hostnames, whether TLS is terminated at the proxy or re-encrypted to Keycloak, whether TLS passthrough is required, whether the proxy sits in front of a cluster, and whether X.509 client certificate login must work end to end. Each of these adds design review, test cases and change approvals in your network and security teams. Request a schedule in the written scope that lists the dependencies on certificate issuance, firewall changes and load balancer access, since those often set the critical path.
What must our team provide before a proxy engagement starts?
Plan to provide the inputs the proxy cannot be configured without. These are:
- Public and admin hostnames, with DNS records that point to the proxy
- TLS certificates and their private keys, or the certificate authority and issuing process you use
- A network diagram showing where the proxy, Keycloak nodes and database sit, and which subnets can reach the admin interface
- The list of paths that must be public, such as login and token endpoints, and those that must be blocked, such as the admin console and management endpoints
- For X.509 login, the trusted client certificate authority chain and how your load balancer forwards the certificate
The Keycloak production guide asks for TLS on all communication and path restrictions at the proxy, so these inputs need owners before work starts.
Can our internal team set up the reverse proxy without a partner?
Yes, a capable platform or network team can usually do it, provided they have someone who knows the proxy product, someone who owns certificates and DNS, and time to test. The risky part is rarely the first working login. It is the edge cases: an admin console left reachable from the public hostname, wrong scheme or client IP values in tokens, redirect loops after a hostname change, or a client certificate that Keycloak never sees. Decide whether your team will test each of these cases against your own environment, and whether you want an outside party to review the configuration before it goes live.
Why does the proxy configuration matter for security?
A proxy is the place where you decide which parts of Keycloak face the internet. If the admin console and the Administration REST API share a hostname with public login pages, anyone who can reach the proxy can reach administration, so the production guide recommends separating them by hostname or context path. Misconfigured trusted proxy addresses can also let a client spoof forwarded headers, which affects redirect URLs and the scheme Keycloak believes it is serving. Blocking management endpoints such as metrics at the proxy is part of the same control set. Test these settings from outside your network, not only from inside it.
What should we request in a written scope for a proxy project?
Ask for a scope that names each deliverable and the test that proves it. A useful written scope lists the proxy product and version, the hostnames and paths in each zone, the TLS mode (terminate, re-encrypt or passthrough) and the reason for it, how client IP and forwarded headers are trusted, and whether PROXY protocol or client certificate forwarding is in scope. It should also state the verification steps, such as checks that blocked paths return denial, that login works through the public hostname, and that the admin hostname is unreachable from public networks. Finally, confirm who approves changes, who holds the keys and certificates, and what handover documentation you receive.
Which Keycloak version should we target when we configure the proxy?
Configure the proxy against the Keycloak version you will run in production, and check the proxy-related settings in the documentation for that version, because hostname and proxy options have changed across releases. The current Keycloak release is 26.8.1, published October 13, 2026, according to keycloak.org. If you run Red Hat build of Keycloak, confirm its supported version with Red Hat, since its product page showed 26.6 as the latest at the time of the source. Ask the team doing the work to state which version they tested against, and plan to retest the proxy rules after each Keycloak upgrade.
How DeployOpen scopes and delivers a Keycloak proxy setup
DeployOpen scopes a Keycloak proxy setup as a fixed piece of work carried out inside your own infrastructure, with the scope, deliverables and timeline agreed in writing before any configuration changes are made. The scope names the proxy you have chosen (NGINX, HAProxy or Traefik), the hostnames in use, the TLS mode (re-encrypt or passthrough), the paths to expose and block, and whether PROXY protocol or forwarded client certificates for X.509 login are needed. Those decisions are recorded in the statement of work so that the quote follows from a defined set of controls rather than an open-ended request to make Keycloak work behind a proxy.
During the build, DeployOpen delivers a documented configuration for the chosen proxy, including the forwarded header handling, the trusted proxy addresses that Keycloak accepts, and the rules that keep the admin console and Administration REST API on a separate hostname or context path from public frontend URLs. Verification covers the login flows your applications use, token issuance behind the proxy, logout, and a test that each blocked path returns a refusal from the proxy rather than reaching Keycloak. Where a client certificate is part of login, the verification also checks that the certificate reaches Keycloak through the proxy as configured. Ask for the test cases and their expected results in the scope, so you can rerun them after any change.
Upgrades and proxy configuration changes are the recurring part of this work. Keycloak releases on a planned cadence, so the proxy rules and trusted address settings need to be checked against each new version. DeployOpen can provide this as an optional retainer, which is priced separately from the fixed-scope build. When you request a quote, ask what the retainer covers, how change requests are handled, and who holds the proxy configuration after handover. Confirm with your own security team which controls and ownership model your environment requires before work begins.

