Setup a nginx reverse proxy for keycloak

Viewed 23

I installed keycloak following this guide I can access it using http://pu.bl.ic.ip:8082

Now, I put it behind nginx with the following conf:

server {
  if ($host = keycloak.mydomain.com) {
          return 301 https://$host:$request_uri;
  }
  listen 80;
  listen [::]:80;
  server_name keycloak.mydomain.com;
  return 404;

}

server {
  listen [::]:443 ssl;
  listen 443 ssl;
  ssl_certificate /etc/letsencrypt/live/keycloak.mydomain.com/fullchain.pem; # managed by Certbot
  ssl_certificate_key /etc/letsencrypt/live/keycloak.mydomain.com/privkey.pem; # managed by Certbot
  ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; 
  server_name keycloak.mydomain.com;
  access_log /var/log/nginx/keycloak-access.log;
  error_log /var/log/nginx/keycloak-error.log;

  location / {
              proxy_pass http://127.0.0.1:8082;
  }
}

I can access it at https://keycloak.mydomain.com

The problem is the the link on the webpage use 127.0.0.1:8082 as baseurl. How do I use keycloak.mydomain.com instead ?

1 Answers

You have to play with proxy=edge setting and some environement variables (which may differs between v18 and v19. Check examples there: https://github.com/keycloak/keycloak/issues/14452

Or search the issues lists with these environement variable until you find the right combination

  • KC_HOSTNAME_STRICT
  • KC_HOSTNAME
  • KC_HOSTNAME_PORT
  • KC_HTTP_RELATIVE_PATH
  • KC_HOSTNAME_URL
  • KC_HOSTNAME_ADMIN_URL
  • KC_PROXY
Related