我为路由设置了Zuul,为服务发现设置了Eureka,这很好。在设置Eureka之前,我使用server.address=127.0.0.1将实际服务绑定到localhost,以便只能在Api网关中访问它们。
当将Zuul和Eureka合并时,server.address=127.0.0.1不再起作用了。我不能访问我的实际休息端点,既不能从我的网络,也不能从外部。
我的尤里卡服务发现的application.properties:
spring.application.name=service-discovery
server.port=8761
eureka.client.registerWithEureka=false
eureka.client.fetchRegistry=false我的Zuul网关的application.properties:
spring.application.name=api-gateway
zuul.prefix=/api
server.port=8080
ribbon.eureka.enabled=true
eureka.client.serviceUrl.defaultZone=http://localhost:8761/eureka/
zuul.routes.library.path=/library/**
zuul.routes.library.serviceId=library我的实际REST服务的application.properties:
spring.application.name=library
server.servlet.context-path=/library
server.port=8090
server.address=127.0.0.1
ribbon.eureka.enabled=true
eureka.client.serviceUrl.defaultZone=http://localhost:8761/eureka/当我从REST服务的属性文件中删除server.address=127.0.0.1时,我当然可以访问资源--但也可以访问没有localhost的资源,这不是我想要的。
因此,我试图实现的是,我的小微服务只能从localhost内部访问(在请求通过Zuul网关之后)。此外,我希望使用Eureka来发现服务,并有机会提供第二个序列化实例。
发布于 2018-03-19 10:58:54
使用eureka.instance.hostname=localhost或eureka.instance.ip-address=127.0.0.1将实际的微服务注册到尤里卡服务器,再加上将微服务绑定到本地主机(server.address=127.0.0.1),就完成了这项工作。
这些是application.properties文件:
我的尤里卡服务发现的application.properties:
spring.application.name=service-discovery
server.port=8761
server.address=127.0.0.1
eureka.client.registerWithEureka=false
eureka.client.fetchRegistry=false我的Zuul网关的application.properties:
spring.application.name=api-gateway
zuul.prefix=/api
server.port=8080
ribbon.eureka.enabled=true
eureka.client.registerWithEureka=false
zuul.routes.library.path=/library/**
zuul.routes.library.serviceId=library
zuul.routes.library.stripPrefix=false我的实际REST服务的application.properties:
spring.application.name=library
server.servlet.context-path=/library
server.port=8090
server.address=127.0.0.1
ribbon.eureka.enabled=true
eureka.client.registerWithEureka=true
eureka.instance.hostname=localhost
eureka.instance.ip-address=127.0.0.1“库”微服务现在只在本地主机上提供,但仍在尤里卡注册,并在Zuul API网关之后注册。
https://stackoverflow.com/questions/49324723
复制相似问题