gpt4 book ai didi

spring - 如何在Docker容器中配置Spring Cloud OAuth2

转载 作者:行者123 更新时间:2023-12-02 18:24:16 24 4
gpt4 key购买 nike

我在使用micro-spring-docker时遇到了一些问题,我认为sso token 网址不正确。

演示https://github.com/keryhu/micro-oauth2-docker

在本地计算机中,sso服务和auth-service可以正常工作。

但不在docker容器中,

the problem is that redirecting to auth-server Timeout .



SSO(PC网关服务)application.yml:
security:
user:
password: none
oauth2:
client:
accessTokenUri: http://${AUTHSERVER_PORT_9999_TCP_ADDR:localhost}:9999/uaa/oauth/token
userAuthorizationUri: http://${AUTHSERVER_PORT_9999_TCP_ADDR:localhost}:9999/uaa/oauth/authorize

docker-compose.yml
eureka:
image: eureka:0.0.1-SNAPSHOT
container_name: eureka
hostname: eureka
ports:
- "8761:8761"

configserver:
image: config-server:0.0.1-SNAPSHOT
container_name: configserver
hostname: configserver
links:
- eureka
ports:
- "8888:8888"

authserver:
image: auth-server:0.0.1-SNAPSHOT
container_name: authserver
hostname: authserver
links:
- eureka
- configserver
ports:
- "9999:9999"

pcgateway:
image: pc-gateway:0.0.1-SNAPSHOT
container_name: pcgateway
hostname: pcgateway
links:
- eureka
- configserver
- authserver
ports:
- "8080:8080"

在docker容器中启动后:

http://192.168.99.100:8761/显示:
Instances currently registered with Eureka
Application AMIs Availability Zones Status
AUTHSERVER n/a(1) (1) UP (1) - authserver:authserver:9999
CONFIGSERVER n/a(1) (1) UP (1) - configserver:configserver:8888
PCGATEWAY n/a(1) (1) UP (1) - pcgateway:pcgateway:8080

但是,当打开身份验证页面时: http://192.168.99.100:8080

应该将其重定向到auth-server登录页面,但是打开了Timeout,地址栏为:
http://172.17.0.4:9999/uaa/oauth/authorize?client_id=clientapp&redirect_uri=http://192.168.99.100:8080/login&response_type=code&state=cdXhfg

我不知道为什么,也许上面的sso tokenurl是不正确的。怎么解决?

最佳答案

172.17.0.4 IP地址是内部(容器-容器)网络上authserver容器的IP地址,无法从docker主机(虚拟机)外部访问。

这可能很棘手,因为(在这种情况下)您需要提供docker运行所在的虚拟机的IP地址,该地址可能会更改,并且在生产中肯定会有所不同。

如果将${AUTHSERVER_PORT_9999_TCP_ADDR:localhost}更改为192.168.99.100,它应该可以工作。

我建议使用您在docker-compose.yml中提供的环境变量来配置IP地址(或域),如下所示:

${DOMAIN_NAME:192.168.99.100}

默认为虚拟机的“标准” IP地址。在生产中,您可以传递项目运行所在服务器的实际域名或IP地址。

Note that the "link" environment variables are marked deprecated, and only will be used on the default (bridge) network. The new linking feature won't create these variables, but you can simply link to other containers by name. See https://docs.docker.com/engine/userguide/networking/work-with-networks/#linking-containers-in-user-defined-networks

关于spring - 如何在Docker容器中配置Spring Cloud OAuth2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35501600/

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