One Keycloak Custom Domain Across Multiple Regions. Serve one Keycloak custom domain from many regions: one hostname on every cluster, an edge that routes by site, TLS for one name and an issuer that stays put.
To run one Keycloak custom domain across several regions, use one hostname everywhere: point the custom domain at an edge or global load balancer, set the same hostname on every Keycloak cluster so the issuer in your tokens never changes, and let the edge route each request to a healthy site that runs your cluster. The edge should pick that origin by site, not by region, because one region can hold more than one site. On Skycloak managed Keycloak, you add the custom domain to your cluster from the dashboard, and Skycloak verifies it and issues its certificate.
This post walks through the whole path for a self-hosted setup on Keycloak 26.x: DNS and the edge, TLS for one name served from many origins, identical hostname and proxy settings on every cluster, why the issuer has to stay the same, and how to check which site answered a login. It ends with how the same thing works on Skycloak. If you have not put Keycloak behind a proxy before, start with our guide to running Keycloak behind a reverse proxy, and for the database and cache side of running several clusters, read our post on Keycloak 26.7 multi-region architecture.
What does one custom domain across regions look like?
The setup has four layers, and each one has a single job. DNS points auth.example.com at the edge. The edge (a CDN, a global load balancer or a GeoDNS service) terminates TLS for that one name and decides which origin gets the request. Each origin is a reverse proxy in front of one Keycloak cluster. Every Keycloak cluster is configured to believe it lives at https://auth.example.com, whichever site it runs in.
Two words matter for the rest of this post. A region is the broad location your users and contracts care about, such as “us” or “eu”. A site is one concrete deployment inside a region: one Kubernetes cluster, in one data center or cloud, with its own proxy and its own Keycloak pods. Many setups start with one site per region, which makes the two words look interchangeable, and that is where routing mistakes come from.
Why does routing by region break when one region has several sites?
A common first version of the edge keeps a table keyed by region: “us” goes to the US origin, “eu” goes to the EU origin. That works until you add a second site in the same region, for example a second US data center for capacity, for a different cloud, or for private connectivity. Now “us” still points at the first site, and every custom domain whose Keycloak cluster runs on the second site is sent to a proxy that does not host it. Users see a 404 or the wrong Keycloak, depending on how that proxy handles an unknown host.
The browser asks for auth.example.com and the edge terminates TLS (1). Routing by region maps “us” to its default site A, where this Keycloak does not run, so the request fails (2). Routing by site maps the domain to site B, where the cluster runs, and Keycloak returns the login page (3).
To fix it, record for each custom domain the site its cluster runs on, and look up the origin from that site. The region is still useful for the questions people ask about data location, but the edge should never use it to pick an origin.
Step 1: Point the domain at the edge
Create one DNS record for the custom domain, usually a CNAME, that points at your edge rather than at any single site. Your users and your apps only ever see auth.example.com, so you can add, move or drain sites later without touching their configuration.
If your edge is Cloudflare for SaaS, each customer domain becomes a custom hostname on your zone, and the Cloudflare for SaaS overview says “Custom hostnames are routed to a default origin server called fallback origin.” For more than one site, you set a custom origin server per hostname, which lets you send traffic “from one or more custom hostnames to somewhere besides your default proxy fallback”. That per-hostname origin is where the site lookup from the previous section belongs: give each site its own origin name, and set the custom hostname’s origin to the name of the site its cluster runs on.
Step 2: Plan TLS for one name served from many origins
Browsers only see the certificate the edge presents, so the edge needs a valid certificate for auth.example.com. With Cloudflare for SaaS, each custom hostname goes through a hostname validation step, so expect a short pending state after you add the DNS record.
Between the edge and each origin you have two choices. Each site can present a certificate for its own origin name, which the edge validates, and this is the simpler option because no site has to hold the customer’s certificate. Or each site can hold a certificate for auth.example.com itself. If you issue that one with ACME, consider the DNS-01 challenge, since a DNS record is answered the same way whichever site the validation request would have reached; Let’s Encrypt’s page on challenge types compares the options.
Step 3: Set the same hostname and proxy options on every cluster
Keycloak builds every URL it hands out (redirects, the discovery document and the iss claim in tokens) from its hostname settings, and the Keycloak hostname guide notes that the base URL “has an important impact on how tokens are issued and validated”. Set hostname to the full URL of the custom domain on every cluster, in every site, with no per-site difference:
# conf/keycloak.conf, identical in every site
hostname=https://auth.example.com
# Optional: serve the admin console on a separate, private address
hostname-admin=https://keycloak-admin.internal.example.com
# Your proxy sets X-Forwarded-* and overwrites what clients send
proxy-headers=xforwarded
# Only trust those headers from your proxy's addresses
proxy-trusted-addresses=10.20.0.0/16
When hostname is set, the guide says hostname-strict is ignored, so Keycloak will not build URLs from request headers. For proxy-headers, the reverse proxy guide warns that your proxy must set and overwrite the Forwarded or X-Forwarded-* headers, because a misconfiguration “will leave Keycloak exposed to security vulnerabilities”, and it adds that by default Keycloak accepts proxy headers from any source, which is why proxy-trusted-addresses belongs in the same file. The guide also has exposed path recommendations on which paths to publish and which to keep internal, such as the admin console, so read them before you write the proxy rules for every site. If you move the admin console off the public name, our walkthrough of a separate admin hostname with NGINX shows the proxy side.
Keep these settings in one shared source, such as one Helm values file or one operator custom resource template, so a change reaches every site together. A hostname that differs on one site is hard to spot, because logins on the other sites keep working.
The cluster, without the on-call
Skycloak runs real upstream Keycloak in the region you choose, and takes the upgrades, backups, certificate rotation and patching off your team. No fork, so you can export and self-host whenever you want.
Step 4: Keep the issuer and tokens valid across sites
An OIDC client trusts one issuer, https://auth.example.com/realms/your-realm, which it also uses to find the realm’s OpenID Connect Discovery document. OpenID Connect Core then has the client check that the iss claim in each ID Token matches that issuer. Because every cluster has the same hostname, every site publishes the same issuer, and a token issued in one site has the right iss when it is checked against another.
The same issuer is not enough on its own: the sites also need the same realm data, including the realm’s signing keys, its clients and its sessions. Keycloak’s high availability guide describes multi-cluster deployments in which two or more clusters share one database, and the multi-cluster v2 requirements ask for a highly available database with synchronous replication and a commit latency below 10 ms between the clusters. If your sites are far apart and each has its own database, they are separate Keycloak installations that happen to share a name. In that case each site keeps its own copy of the realm, and you have to plan yourself how its keys and sessions line up between the sites. For a single region with several zones, our guide to high availability for Keycloak on Kubernetes covers the cluster side.
Step 5: Verify which site served a login
Because every site answers on the same name, you need a way to tell them apart. Have each site’s proxy add a response header with its own site name, for example in NGINX:
# In the server block for auth.example.com, different value per site
add_header X-Served-By "site-b" always;
Then request the realm’s discovery document and read the header and the issuer together:
curl -sI https://auth.example.com/realms/your-realm/.well-known/openid-configuration | grep -i x-served-by
curl -s https://auth.example.com/realms/your-realm/.well-known/openid-configuration | jq -r .issuer
The header tells you which site answered, and the issuer should read https://auth.example.com/realms/your-realm from every site. If the issuer shows a site’s internal address instead, that cluster is missing the hostname setting. Keycloak also has a hostname-debug option that turns on a debug page at /realms/master/hostname-debug, which shows how that node resolves its frontend and backchannel URLs; turn it on only while you troubleshoot.
What happens to the custom domain when a site goes down?
The custom domain itself does not change during a failover: the edge stops sending requests to the failed site’s origin and sends them to a healthy one. For that to work, the edge needs a health check per site, and the reverse proxy guide’s exposed path recommendations are the place to check which path a load balancer should probe. Whether users stay signed in depends on Step 4, shared data or not. The deeper design, with traffic steering and the database layer, is in our multi-region architecture post, and our post on identity resilience during an IdP outage covers planning for the case where the identity layer itself is down.
How does this work on Skycloak managed Keycloak?
On Skycloak managed Keycloak (Dedicated), you add a custom domain to a cluster from the dashboard: select the cluster, open Custom domain, enter the domain and add the CNAME record the dashboard shows at your DNS provider. Skycloak then verifies the domain and issues its certificate through Cloudflare for SaaS in the background, and the domain moves from pending to active by itself, as the custom domain docs describe. You do not run the edge, the certificate or the origin.
Skycloak clusters run in several locations, including US East and US West (cluster locations), and you add the custom domain to the cluster itself, whichever location it runs in. If you want different realms on different names, realm domain mapping maps each custom domain to one realm on the cluster. Because traffic comes in through the edge rather than a fixed address, a managed cluster also has no static IP to allowlist, which our post on whether a managed Keycloak cluster has a static IP explains.
Frequently asked questions
Can two Keycloak clusters share one custom domain?
Yes, if both clusters have the same hostname setting and an edge or global load balancer in front decides which cluster gets each request. To keep users signed in when a request moves between clusters, the clusters also need shared realm data, which in Keycloak’s multi-cluster design means one synchronously replicated database.
Does the Keycloak issuer change when traffic moves to another region?
No, as long as every cluster has the same hostname. The Keycloak hostname guide says the base URL “has an important impact on how tokens are issued and validated”, so with one hostname on every cluster each site publishes the same issuer, https://auth.example.com/realms/your-realm, whichever site answered.
Should the edge route Keycloak traffic by region or by site?
By site. A region can hold more than one site, and a region-keyed table can only point at one of them, so domains whose cluster runs on another site in the same region are sent to a proxy that does not host them.
Do I need a separate TLS certificate for each site?
The edge needs one certificate for the custom domain. Each site needs a certificate the edge trusts, either for its own origin name or for the custom domain itself; for the second option, issue it with the DNS-01 challenge so validation does not depend on which site answers.
Next steps
For a self-hosted setup, start by writing down, for each custom domain, the site its cluster runs on, and make the edge look up the origin from that. Then put the same hostname and proxy settings on every cluster from one shared source, add a per-site response header, and check the issuer from each site with the commands above.
On Skycloak, read how custom domains work on managed Keycloak, then add your domain to your cluster and check that logins resolve to the site your cluster runs on. To see what else the managed service runs for you, look at managed Keycloak hosting.



