如何在反向代理后设置不同端口的Eureka客户端?

huangapple go评论87阅读模式
英文:

How to setup eureka clients behind reverse proxy with different port?

问题

我目前正在尝试使用Eureka进行服务发现,但是客户端注册的端口不正确。每个Eureka客户端都位于不同的服务器上,位于其自己的nginx反向代理后面,可以通过https在443端口上从外部访问,但是Java Eureka客户端配置在不同的端口上。我还尝试将它们配置在与nginx公开的相同端口上,但是然后nginx服务器会产生无限重定向,在一些尝试后以“无效重定向”错误停止。由于在不同的端口上,Eureka客户端会在使用spring boot yaml服务器端口配置中配置的端口上注册。然后,如果客户端尝试访问另一个客户端,它将使用在spring boot应用程序中配置的端口。我需要能够在与运行客户端的端口不同的端口上注册Eureka客户端。这可能吗?我在这里漏掉了什么?在这里使用Zuul作为网关会有所不同吗?

部署(每个系统都部署在不同的VServer上,位于NGINX反向代理后面):
Eureka服务器
多个Eureka客户端(API、UI等)
身份管理Keycloak SSO服务器未在Eureka服务器上注册。

英文:

I am currently trying to setup service discovery with eureka, but the clients register with the wrong port. Every Eureka client is on a different server behind its own nginx reverse proxy and it is reachable from outside via https on port 443, but the java eureka clients are configured on different port. I also tried configuring them on the same port as nginx exposes, but than the nginx server has infinited redirects and stops after some attempts with error "invalid redirect". Being on different port the eureka clients register at the server with the port configure in spring boot yaml server port config. If then a client tries to reach another client it uses the port configured in the spring boot application. I need to be able to register the eureka client on a different port than I am running the client. Is that possible? What am I missing here? Would be using Zuul as a gateway make a difference here?

Setup (every system is deployed on a different VServer behind NGINX reverse proxy):
Eureka Server
Multiple Eureka Clients (API, UI, etc)
Identity Management Keycloak SSO server not registered with eureka server

答案1

得分: 0

一个端口一次只能被一个服务使用。因此,您不能配置nginx和spring boot监听同一个端口并收到错误消息。

Spring Boot并不知道代理设置,因此eureka客户端使用spring.port在eureka服务器上注册实例。您可以使用EurekaInstanceConfig配置eureka实例。在这种情况下,您希望将eureka.instance.port=443更改为nginx公开的端口。

英文:

A port can only be used by one service at a time. Hence, you cannot configure nignx and spring boot to listen on the same port and receive the error message.

Spring boot does not know about the proxy setup and hence the eureka client registers the instance (with the spring.port) at the eureka server. You can configure the eurka instance with the EurekaInstanceConfig. In this case you want to change eureka.instance.port=443 to the one exposed by nginx.

huangapple
  • 本文由 发表于 2020年8月28日 04:38:15
  • 转载请务必保留本文链接:https://go.coder-hub.com/63623850.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定