docker - 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”
解决方案
一个明显的问题(可能还有更多问题,因此修复这个问题可能仍然无法解决所有问题): 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”是正确的响应。
推荐阅读
- javascript - 如果附加了组标签 ID,如何克服 D3JS 树的消失
- php - PHP 中的 ImageMagick Watermark - 如何使用原始图像大小的 % 而不是水印图像大小的 % 来缩放水印?
- flutter - 如何将异步函数中的列表加载到小部件中?
- npm - npm 错误!尝试获取 http://registry.npmjs.org/accepts 时响应正文无效:sha 完整性验证失败
- mysql - (1054,“'字段列表'中的未知列'leçon_lesson.subject_id'”)
- c - 将现有内存(数据段)映射到另一个内存段
- c++ - ffmpeg 仅发布播放列表,但不发布 HLS 片段
- python - !head 在 python 和 NumPy 中做了什么?
- c# - 当我将应用程序发布到 Azure 时,为什么我的控制器端点会中断
- android - AndroidX 多个 Preferences 实例