使用自定义基本URL为Keycloak Docker配置反向代理 [英] Configure reverse-proxy for Keycloak docker with custom base URL

查看:413
本文介绍了使用自定义基本URL为Keycloak Docker配置反向代理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何设置docker keycloak base url作为参数?

我具有以下nginx反向代理配置:

I have the following nginx reverse proxy configuration:

server {
    listen 80;
    server_name example.com;

    location /keycloak {
        proxy_pass http://example.com:8087/;
    }
}

当我尝试访问 http://example.com/keycloak/时,我得到了keycloak http重定向改为 http://example.com/auth/而不是

When I try to access http://example.com/keycloak/ I got a keycloak http redirect to http://example.com/auth/ instead of http://example.com/keycloak/auth/

有什么想法吗?

推荐答案

仅测试了@home,实际上需要添加多个配置:

Just tested that @home, and actually multiple configuration additions are needed:

1/使用env -e PROXY_ADDRESS_FORWARDING=true (如文档中所述),这是访问keycloak的代理方式所必需的:

1/ Run the keycloak container with env -e PROXY_ADDRESS_FORWARDING=true as explained in the docs, this is required in a proxy way of accessing to keycloak:

docker run -it --rm -p 8087:8080 --name keycloak -e PROXY_ADDRESS_FORWARDING=true jboss/keycloak:latest

也在此 SO问题

2/2/更改keycloak配置文件$JBOSS_HOME/standalone/configuration/standalone.xml

2/ Change the web-context inside keycloak's configuration file $JBOSS_HOME/standalone/configuration/standalone.xml

默认密钥斗篷配置指向auth

Default keycloak configuration points to auth

<web-context>auth</web-context>

然后您可以将其更改为keycloak/auth

Then you could change it to keycloak/auth

<web-context>keycloak/auth</web-context>

如果您需要为docker自动执行此操作,只需创建一个新的keycloak映像即可:

If you need to automate this for docker, just create a new keycloak image :

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处理)

3/ Add some proxy information to nginx configuration (mostly for http / https handling)

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请求进行代理.

If you are proxying requests from nginx to keycloak on same server, I recommend using proxy_pass http://localhost:8087;, and if not try to use a private network to avoid proxying through external web requests.

希望这会有所帮助

这篇关于使用自定义基本URL为Keycloak Docker配置反向代理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆