进入页面时,Keycloak无法保留通过的端口号:30666
但是,提交按钮不包含ip端口号,仅在此处使用ip-address.由于发布失败.
重定向失败…
如何使Keycloak在代理后面工作?




密钥斗篷在具有以下conf的NGinx代理后面的kubernetes集群中运行:
worker_processes 1;
error_log /dev/stderr warn;
events {
worker_connections 1024;
}
# make sure to set plaintext JWT_SECRET environment variable
env JWT_SECRET;
http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /dev/stdout main;
lua_package_path "/usr/local/openresty/lualib/?.lua;;";
server {
listen 8080;
root /;
# load index page from nginx implementing the KC javascript:
location / {
index index.htm index.html;
}
location /auth {
proxy_pass http://idp:8080/auth;
proxy_http_version 1.1; # this is essential for chunked responses to work
proxy_buffering off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Scheme $scheme;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
}
# Secured endpoints
location /secure/ {
access_by_lua_file /bearer.lua;
default_type text/plain;
echo "<p>i am protected by jwt<p>";
}
}
}
我的idp部署如下所示:
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
annotations:
kompose.cmd: kompose convert -f docker-compose.yml
kompose.version: 1.2.0 ()
creationTimestamp: null
labels:
io.kompose.service: idp
name: idp
spec:
replicas: 1
strategy: {}
template:
metadata:
creationTimestamp: null
labels:
io.kompose.service: idp
spec:
containers:
- env:
- name: KEYCLOAK_PASSWORD
value: pass
- name: KEYCLOAK_USER
value: admin
- name: PROXY_ADDRESS_FORWARDING
value: 'true'
image: jboss/keycloak
name: idp
ports:
- containerPort: 9990
- containerPort: 8080
resources: {}
restartPolicy: Always
status: {}
最佳答案
问题是proxy_set_header $host,应该是$host:$server_port
此外,不需要在代理URL后面加上/ auth URI.如果未指定,则Nginx将传输URI而不进行更改.
配置应为:
location /auth {
proxy_pass http://idp:8080;
...
proxy_set_header Host $host:$server_port;
参考http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_pass
注意:Keycloak客户端可能需要HTTPS URL.如果您在Nginx中启用HTTPS,则请记住也将方案与x-forwarded-proto标头一起传递给Keycloak.
proxy_set_header x-forwarded-proto $scheme;
(编辑:李大同)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|