首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >*44 connect()连接上游jhipster失败(111:连接被拒绝)

问*44 connect()连接上游jhipster失败(111:连接被拒绝)
EN

Stack Overflow用户
提问于 2020-11-21 12:35:36
回答 1查看 490关注 0票数 0

当我试图访问显示"502 Bad Gateway“/ nginx/1.19.3的jhipster链接https://gateway.technet.local/ag01时,连接被拒绝。其中,as可以毫无问题地访问https://gateway.technet.local:8443。

下面是我的docker-compose文件docker-compose.yml

代码语言:javascript
复制
version: '3.7'
services:
  keycloak:
    image: jboss/keycloak:10.0.2
    command:
      [
        '-b',
        '0.0.0.0',
        #'-Dkeycloak.forceBackendUrlToFrontendUrl=true',
        #'-Dkeycloak.frontendUrl=http://keycloak.t-vrec-ws-01/auth',
        '-Dkeycloak.migration.action=import',
        '-Dkeycloak.migration.provider=dir',
        '-Dkeycloak.migration.dir=/opt/jboss/keycloak/realm-config',
        '-Dkeycloak.migration.strategy=OVERWRITE_EXISTING',
        '-Djboss.socket.binding.port-offset=1000',
        '-Dkeycloak.profile.feature.upload_scripts=enabled',
      ]
    volumes:
      - ./realm-config:/opt/jboss/keycloak/realm-config
      - ./technet-certs/keycloak-technet.crt:/etc/x509/https/tls.crt
      - ./technet-certs/keycloak-technet.key:/etc/x509/https/tls.key
    environment:
#      - PROXY_ADDRESS_FORWARDING=true
      - KEYCLOAK_USER=admin
      - KEYCLOAK_PASSWORD=admin
      - DB_VENDOR=h2
    ports:
      - 80:9080
      - 9443:9443
      - 10990:10990
  gateway:
    image: gateway-cacert
    environment:
      - _JAVA_OPTIONS=-Xmx512m -Xms256m
      - 'SPRING_PROFILES_ACTIVE=prod,swagger'
      - 'SPRING_DATASOURCE_URL=jdbc:postgresql://gateway-postgresql:5432/gateway'
      - 'SPRING_SECURITY_OAUTH2_CLIENT_PROVIDER_OIDC_ISSUER_URI=https://keycloak.technet.local/auth/realms/jhipster'
        #- 'SPRING_SECURITY_OAUTH2_CLIENT_PROVIDER_OIDC_ISSUER_URI=https://gateway.t-vrec-ws-01/auth/realms/jhipster'
      - SPRING_SECURITY_OAUTH2_CLIENT_REGISTRATION_OIDC_CLIENT_ID=web-app
      - SPRING_SECURITY_OAUTH2_CLIENT_REGISTRATION_OIDC_CLIENT_SECRET=web-app
      - JHIPSTER_SLEEP=30
    ports:
      - 8443:443
    depends_on:
      - gateway-postgresql

  gateway-postgresql:
    image: postgres:12.3
    environment:
      - POSTGRES_USER=gateway
      - POSTGRES_PASSWORD=
      - POSTGRES_HOST_AUTH_METHOD=trust
    ports:
      - 5432:5432


  nginx:
    image: nginx
    depends_on:
      - gateway
    volumes:
      - ./nginx.conf:/etc/nginx/nginx.conf
      - ./nginx-ssl:/etc/nginx/ssl
    ports:
      - 443:443

下面是我更新的nginx.conf文件

代码语言:javascript
复制
events {
}

http {
   server {
         listen 443 ssl;

         server_name gateway.technet.local

         add_header Strict-Transport-Security "max-age=86400; includeSubdomains; preload" always;
         ssl_certificate /etc/nginx/ssl/nginx-selfsigned.crt;
         ssl_certificate_key /etc/nginx/ssl/nginx-selfsigned.key;
         ssl_session_timeout 20m;

         location /ag01 {
                proxy_set_header Host $host;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header X-Forwarded-Proto $scheme;
                proxy_set_header X-Real-IP $remote_addr;

                proxy_pass https://gateway:443;
                resolver  127.0.0.1;
         }

         location /auth {
                proxy_set_header Host $host;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header X-Forwarded-Proto $scheme;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_pass https://keycloak:9443;
                resolver   127.0.0.1;
         }
   }
}

我被困在这里了,有人能帮我解决这个问题吗?

EN

回答 1

Stack Overflow用户

发布于 2020-11-21 18:29:06

您的nginx配置使用主机端口8843作为网关,但由于nginx运行在容器网络中,因此应该使用容器端口443。

https://docs.docker.com/compose/networking/

此外,您的nginx变量指向keycloak.technet.local域名,但是您没有使用这种虚拟主机显示任何SPRING_SECURITY_OAUTH2_CLIENT_PROVIDER_OIDC_ISSUER_URI配置。如何将此名称解析为IP地址?

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64939874

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档