如何将docker keycloak base url
设置为参数?
我有以下nginx反向代理配置:
server {
listen 80;
server_name example.com;
location /keycloak {
proxy_pass http://example.com:8087/;
}
}
当我尝试访问http://example.com/keycloak/时,我得到了一个密匙斗篷http重定向到http://example.com/auth/而不是http://example.com/keycloak/auth/
有什么想法吗?
发布于 2017-06-19 09:53:52
刚刚测试了@home,实际上需要添加多个配置:
1/如docs中所解释的那样,使用env -e PROXY_ADDRESS_FORWARDING=true运行keycloak容器,这是访问keycloak的代理方式所必需的:
docker run -it --rm -p 8087:8080 --name keycloak -e PROXY_ADDRESS_FORWARDING=true jboss/keycloak:latest
在这个所以问题中也解释了
2/更改密钥披风配置文件中的web上下文 $JBOSS_HOME/standalone/configuration/standalone.xml
。
默认的密钥披风配置点到auth
<web-context>auth</web-context>
然后您可以将其更改为keycloak/auth
。
<web-context>keycloak/auth</web-context>
如果您需要自动完成对接,只需创建一个新的keycloak映像:
FROM jboss/keycloak:latest
USER jboss
RUN sed -i -e 's/<web-context>auth<\/web-context>/<web-context>keycloak\/auth<\/web-context>/' $JBOSS_HOME/standalone/configuration/standalone.xml
3/向nginx配置中添加一些代理信息(主要用于http / https处理)
location /keycloak {
proxy_pass http://example.com:8087;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
如果您在同一台服务器上代理从nginx到keycloak的请求,我建议使用proxy_pass http://localhost:8087;
,如果不使用专用网络,则避免通过外部web请求进行代理。
希望这能有所帮助
发布于 2019-05-16 14:41:54
从/keycloak
重定向到/keycloak/auth
不起作用。index.html
和Base-URL
中的重定向路由缺少/keycloak
部分。我不得不补充一下:
FROM jboss/keycloak:latest
USER jboss
RUN sed -i -e 's/<web-context>auth<\/web-context>/<web-context>keycloak\/auth<\/web-context>/' $JBOSS_HOME/standalone/configuration/standalone.xml
RUN sed -i -e 's/<web-context>auth<\/web-context>/<web-context>keycloak\/auth<\/web-context>/' $JBOSS_HOME/standalone/configuration/standalone-ha.xml
RUN sed -i -e 's/name="\/"/name="\/keycloak\/"/' $JBOSS_HOME/standalone/configuration/standalone.xml
RUN sed -i -e 's/name="\/"/name="\/keycloak\/"/' $JBOSS_HOME/standalone/configuration/standalone-ha.xml
RUN sed -i -e 's/\/auth/\/keycloak\/auth/' $JBOSS_HOME/welcome-content/index.html
RUN sed -i -e 's/<web-context>auth<\/web-context>/<web-context>keycloak\/auth<\/web-context>/' $JBOSS_HOME/domain/configuration/domain.xml
发布于 2019-01-22 15:40:13
基于@Francois的回答:对于最新的Keycloak (目前为4.8.x),我还必须添加一行来替换standalone-ha.xml
中的standalone-ha.xml
:
FROM jboss/keycloak:latest
USER jboss
RUN sed -i -e 's/<web-context>auth<\/web-context>/<web-context>keycloak\/auth<\/web-context>/' /opt/jboss/keycloak/standalone/configuration/standalone.xml
RUN sed -i -e 's/<web-context>auth<\/web-context>/<web-context>keycloak\/auth<\/web-context>/' /opt/jboss/keycloak/standalone/configuration/standalone-ha.xml
RUN sed -i -e 's/\/auth/\/keycloak\/auth/' /opt/jboss/keycloak/welcome-content/index.html
原因是除非传递了docker-entrypoint.sh
标志,否则standalone-ha.xml
启动脚本将使用standalone.xml
之外的-c
配置。见此处:https://github.com/jboss-dockerfiles/keycloak/blob/master/server/tools/docker-entrypoint.sh
https://stackoverflow.com/questions/44624844
复制相似问题