Nginx登录后的密钥泄漏失败,帖子中缺少端口号等

进入页面时,Keycloak无法保留通过的端口号:30666

但是,提交按钮不包含ip端口号,仅在此处使用ip-address.由于发布失败.

重定向失败…

如何使Keycloak在代理后面工作?

enter image description here


enter image description here


enter image description here


enter image description here

密钥斗篷在具有以下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;

相关文章

文章浏览阅读3.7k次,点赞2次,收藏5次。Nginx学习笔记一、N...
文章浏览阅读1.7w次,点赞14次,收藏61次。我们在使用容器的...
文章浏览阅读1.4k次。当用户在访问网站的过程中遇到404错误时...
文章浏览阅读2.7k次。docker 和 docker-compose 部署 nginx+...
文章浏览阅读1.3k次。5:再次启动nginx,可以正常启动,可以...
文章浏览阅读3.1w次,点赞105次,收藏182次。高性能:Nginx ...