首页 > 解决方案 > Kaycloak docker 管理控制台显示带有反向代理的空白页面

问题描述

我正在将 haproxy 与 keycloak 一起使用,欢迎页面显示正常,但每次我进入管理控制台时,它都会显示一个空白页面,其中没有状态码 200 的信息。我正在使用letsencrypt ssl证书,这是我的haproxy config和docker-compose。

页面截图:- 链接到截图

haproxy 配置:-


global
    log stdout local0 debug
    daemon
    maxconn 4096

defaults
    mode    http
    option  httplog
    option  dontlognull
    timeout connect 5000ms
    timeout client 50000ms
    timeout server 50000ms

    log     global
    log-format {"type":"haproxy","timestamp":%Ts,"http_status":%ST,"http_request":"%r","remote_addr":"%ci","bytes_read":%B,"upstream_addr":"%si","backend_name":"%b","retries":%rc,"bytes_uploaded":%U,"upstream_response_time":"%Tr","upstream_connect_time":"%Tc","session_duration":"%Tt","termination_state":"%ts"}


frontend public
    bind *:80
    bind *:443 ssl crt /usr/local/etc/haproxy/haproxy.pem alpn h2,http/1.1
    http-request redirect scheme https unless { ssl_fc }
    default_backend web_servers


backend web_servers
    option forwardfor
    server auth1 auth:8080

docker-compose.yaml :-

version: "3"
networks:
  internal-network:
services:
  reverse-proxy:
    build: ./reverse-proxy/.
    image: reverseproxy:latest
    ports:
      - "80:80"
      - "443:443"
    networks:
      - internal-network
    depends_on:
      - auth

  auth:
    image: quay.io/keycloak/keycloak:latest
    networks:
      internal-network:
    environment:
      PROXY_ADDRESS_FORWARDING: "true"
      KEYCLOAK_USER: ***
      KEYCLOAK_PASSWORD: ***
      # Uncomment the line below if you want to specify JDBC parameters. The parameter below is just an example, and it shouldn't be used in production without knowledge. It is highly recommended that you read the PostgreSQL JDBC driver documentation in order to use it.
      #JDBC_PARAMS: "ssl=false"

我要访问的页面的网址是 https:///auth/admin/master/console/

注意:当尝试从 haproxy 中删除 ssl 时,keycloak 会打开一个页面并显示错误“需要 https”

标签: dockerdocker-composekeycloakhaproxy

解决方案


一个明显的问题(可能还有更多问题,因此修复这个问题可能仍然无法解决所有问题): https ://www.keycloak.org/docs/latest/server_installation/index.html#_setting-up-a-load-平衡器或代理

配置您的反向代理或负载均衡器以正确设置 X-Forwarded-For 和 X-Forwarded-Proto HTTP 标头。

您没有在 haproxy 前端部分配置此部分。你需要这样:

  http-request set-header X-Forwarded-Port %[dst_port]
  http-request set-header X-Forwarded-For %[src]
  http-request set-header X-Forwarded-Proto https

OIDC 需要 Https 协议,因此当您通过 http 协议到达 Keycloak 时,“需要 https”是正确的响应。


推荐阅读