gpt4 book ai didi

nginx - nginx 登录背后的 keycloak 失败,post 中缺少端口号等

转载 作者:行者123 更新时间:2023-12-03 15:47:30 28 4
gpt4 key购买 nike

Keycloak 失去了进入页面时传递的端口号: 30666

但是提交按钮不包含 ip+端口号,这里只使用了 ip-address。由于帖子失败。

并且重定向失败...

如何让 Keycloak 在代理背后工作?

enter image description here
enter image description here
enter image description here
enter image description here

keycloak 在 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 header 将方案传递给 Keycloak。
        proxy_set_header x-forwarded-proto $scheme;

关于nginx - nginx 登录背后的 keycloak 失败,post 中缺少端口号等,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46891619/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com