What the hostname setting decides
Keycloak writes its own address into almost everything it sends out. The iss claim in every token, the URLs in the discovery document, the links in password reset emails, the redirects during sign-in and the address of the admin console all come from one place: the hostname configuration.
If that address is wrong, the symptoms show up far from the cause. Apps reject tokens because the issuer does not match. Browsers loop between two addresses. Email links point at an internal host name nobody can reach. The admin console loads a blank page because its scripts come from the wrong origin.
Getting the hostname right is usually the first real task of a production deploy, and the first thing to recheck after a move to a new network, a new proxy or a new cluster.
How Keycloak 26 handles the hostname
Keycloak 25 introduced a new set of hostname options, and Keycloak 26 removed the old ones. If you have notes or scripts that use hostname-url, hostname-admin-url, hostname-port, hostname-path or proxy=edge, they no longer apply.
The current options are few, and each has one job.
hostname
The public address of the server. It can be a bare host name such as auth.example.com, or a full URL such as https://auth.example.com. A full URL also fixes the scheme, the port and the path, so it is the clearer choice for production.
With a full URL in hostname, Keycloak builds front-end URLs from it no matter which address a request came in on.
hostname-admin
An address of its own for the admin console, as a full URL. Use it when the console should live on a separate host that only your team can reach, for example a host name that resolves only inside a VPN.
hostname-backchannel-dynamic
When set to true, back-end requests such as token, introspection and UserInfo calls may use the address they arrived on, instead of the public one. This helps when apps inside a private network call Keycloak at an internal address. It needs hostname to be a full URL.
hostname-strict
On by default. With it on, Keycloak refuses to start in production mode until hostname is set. Turning it off makes Keycloak build URLs from the Host header of each request, which is only safe on your own machine.
proxy-headers and http-enabled
These are not hostname options, but they decide how Keycloak reads requests that pass through a proxy. proxy-headers takes xforwarded or forwarded and tells Keycloak which forwarded headers to trust. http-enabled=true lets Keycloak listen on plain HTTP, which you need when TLS ends at the proxy.
A typical production setup
Most production deployments put a reverse proxy or load balancer in front of Keycloak. The proxy holds the certificate and sends plain HTTP to Keycloak on port 8080. The options for that setup are short.
KC_HOSTNAME=https://auth.example.com
KC_HTTP_ENABLED=true
KC_PROXY_HEADERS=xforwardedThe same options as command-line flags look like this. Keycloak accepts either form, and the command line wins when both are set.
bin/kc.sh start \
--hostname=https://auth.example.com \
--http-enabled=true \
--proxy-headers=xforwardedThe address auth.example.com is a placeholder. Use the address your users type or click.
What this tool does
The hostname helper asks a few questions about your setup and writes the matching options. It works out the value of hostname from the public address you enter, adds hostname-admin when the console has its own address, and sets http-enabled and proxy-headers when TLS ends at a proxy.
It can also add proxy-trusted-addresses, so Keycloak reads forwarded headers only from your proxy, and http-relative-path when Keycloak itself serves under a path such as /auth. The result comes out as a command line, environment variables, a Compose block, a Kubernetes env list or keycloak.conf lines.
Under the options it shows the issuer and discovery URL for a sample realm, so you know what to open in a browser to check the result.
What it does not do
- It does not contact your server. Everything runs in your browser, so it cannot see what your proxy actually sends.
- It does not write the certificate options for you. When Keycloak serves HTTPS itself, you still add
https-certificate-fileandhttps-certificate-key-fileor a key store. - It does not configure the proxy. The reverse proxy config tool writes nginx, Caddy and Traefik configs that match these options.
How to use it
- Enter the public address as a full URL, with the path if Keycloak sits under one.
- Tick the admin console box if the console has an address of its own, and enter that address.
- Pick where HTTPS ends: at a proxy, passed through the proxy, or at Keycloak itself.
- If a proxy ends TLS, pick the kind of headers it writes and, if you can, list the proxy addresses to trust.
- Tick the internal network box if your apps call Keycloak at a private address.
- Copy the options in the format you deploy with, restart Keycloak, and open the discovery URL to check every URL in it.
Where it helps
The same few options come up in very different situations. These are the most common.
A first production deploy
Development mode with start-dev does not need a hostname, so many teams first meet these options when they switch to start. Keycloak then refuses to start without hostname, and the helper gives you a complete, consistent set in one step.
Behind a load balancer
A cloud load balancer usually ends TLS and forwards plain HTTP. Keycloak needs http-enabled, proxy-headers and a full URL in hostname, or it builds http:// URLs and the browser gets redirected in a loop. Check which header style your load balancer writes before you pick one.
Moving from a VM to Kubernetes
On a VM, Keycloak may have been reachable on its own address. In a cluster, it sits behind an ingress or a gateway, and apps inside the cluster may call it through a service name. The public hostname stays the same; hostname-backchannel-dynamic covers the internal calls.
Upgrading from an older version
Upgrades from Keycloak 24 or earlier often fail at start because the old hostname and proxy options are gone. Translate them once: hostname-url becomes a full URL in hostname, hostname-admin-url becomes hostname-admin, and proxy=edge becomes http-enabled=true plus proxy-headers.
Common errors and how to fix them
Keycloak will not start: hostname is not configured
Production mode needs hostname while hostname-strict is on. Set hostname to the public URL. Do not turn off hostname-strict to make the error go away on a real server.
A redirect loop or "HTTPS required"
Keycloak thinks the request came over plain HTTP. Either the proxy does not send X-Forwarded-Proto: https, or proxy-headers is not set, so Keycloak ignores what the proxy sends. Set proxy-headers to match the proxy and check that the proxy writes the header.
Tokens rejected because of the issuer
Apps compare the iss claim with the issuer they were configured with. If the two differ by scheme, port or path, validation fails. Open the discovery document and copy the issuer value into the app, or fix hostname so it matches what the app expects.
Email links point at an internal address
Links in emails are built from the front-end address. If hostname is not set to the public URL, or the proxy forwards the wrong host, links carry an internal name. Set hostname as a full URL and the links follow it.
The admin console loads a blank page
This often means the console is served on one address but loads its resources from another that the browser cannot reach. Check hostname-admin and make sure the proxy passes /admin/ and /resources/ on that host.
Security notes
- Only set
proxy-headerswhen a proxy you control sits in front and overwrites the forwarded headers. Otherwise any client can claim to be any host or scheme. - Use
proxy-trusted-addresseswhere you can, so forwarded headers from anywhere else are ignored. - Keep
hostname-stricton in production. Building URLs from the Host header lets an attacker influence links in emails and redirects. - Put the admin console on its own host with
hostname-admin, and limit who can reach that host at the network level.
Best practices
- Always give
hostnameas a full URL withhttps://. It removes guesswork about scheme and port. - Pick one public address per server and use it everywhere: in apps, in identity provider settings and in documentation.
- After any change, open
/realms/<realm>/.well-known/openid-configurationand check that every URL starts with the public address. - Keep the options in one place, either environment variables or
keycloak.conf, so nobody overrides them by accident. - Write the old-to-new option mapping into your upgrade notes before you upgrade from an older major version.
Checking the result
A quick test after a restart catches most mistakes. Fetch the discovery document from outside your network and look at three fields.
curl -s https://auth.example.com/realms/acme/.well-known/openid-configuration \
| jq -r .issuer,.authorization_endpoint,.token_endpointAll three should start with your public address. If any of them shows http://, an internal host or a wrong port, the hostname or proxy settings still need work.