2017-10-23 2 views
1

Keycloakから欠落していたポート番号は、ページを入力する際に​​渡されたポート番号のホールドを失いますここで使用されます。投稿が失敗したため。keycloakが失敗した、ポストなど

、リダイレクト失敗...

にはどうすればKeycloakは、プロキシの背後で動作させることができますか?

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

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: {} 

答えて

1

問題は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; 
関連する問題