Configuring Nginx to have Keycloak handling auth requests in the same domain as your single page app and http api

If you want keycloak to handle auth requests in the same domain as you’re service your single page app (spa) and http api:
The prerender config comes from my prerendering proxy.
Keycloak is listening on port 4000 locally.

nginx config

You mount keycloak under /auth/

Then in keycloak.yml for the gatekeeper

And if using Angular with PWA

need to be added to the root {} to exclude treating the /auth/ prefix path as an angular internal route.

So it looks something like this for the default config:

And now you have keycloak running under the same domain as your SPA and http api.

Spread the love

Leave a Reply

Your email address will not be published. Required fields are marked *