注册带有特定端口的Eureka中的Spring Boot HTTPS应用程序



我尝试仅通过HTTPS注册一个可用的应用程序。我对正确配置有问题,并且在尤里卡(Eureka(的仪表板中显示的链接不正确。我尝试了一些配置,但是我无法获得正确的效果,即尤里卡(Eureka(的工作仪表板链接。

我的基本配置。

server:
  port: 9999
  context-path: /ctx
  ssl:
    key-store: classpath:keystore.jks
    key-store-password: 'kspass'
    key-password: 'kpass'
    keyAlias: ssl
spring:
  application:
    name: app-ctx
  cloud:
    loadbalancer:
      retry:
        enabled: true
eureka:
  client:
    serviceUrl:
      defaultZone: https://localhost:8761/eureka/
  instance:
    hostname: localhost
    secure-port-enabled: true
    non-secure-port-enabled: false
    secure-port: ${server.port}
    health-check-url: https://${eureka.hostname}:XYZ/ctx/health
    status-page-url: https://${eureka.hostname}:XYZ/ctx/info
    home-page-url: https://${eureka.hostname}:XYZ/ctx

我尝试遵循健康/状态/家庭网址的版本:

  1. 绝对没有端口的URL

    示例:health-check-url:https://$ {eureka.hostname}/ctx/health

    结果:https://localhost/ctx/info

  2. $ {server.port}替换的绝对URL

    示例:health-check-url:https://$ {eureka.hostname}:$ {server.port}/ctx/health(

    结果:$ {server.port}未解决,仪表板中的URL为:https://localhost:$ {server.port}/ctx/info

  3. 相对URL

    示例:Health-Check-url-Path:/ctx/health

    结果:http://localhost:9999/ctx/info,no https。

最后一个非常接近我的期望,但是 no HTTPS

最后,我有解决问题的解决方案。不确定这是最好的,因为据我所知,它与随机端口(即server.port = 0。要纠正位置,这不是预期的行为。

而不是使用与当前应用程序相关的$ {server.port}占位符,我们必须使用eureka的配置部分$ {eureka.instance.secure-port}即

server:
  port: 9999
  context-path: /ctx
  ssl:
    key-store: classpath:keystore.jks
    key-store-password: 'kspass'
    key-password: 'kpass'
    keyAlias: ssl
spring:
  application:
    name: app-ctx
  cloud:
    loadbalancer:
      retry:
        enabled: true
eureka:
  client:
    serviceUrl:
      defaultZone: https://localhost:8761/eureka/
  instance:
    hostname: localhost
    secure-port-enabled: true
    non-secure-port-enabled: false
    secure-port: ${server.port}
    health-check-url: https://${eureka.instance.hostname}:${eureka.instance.secure-port}/ctx/health
    status-page-url: https://${eureka.instance.hostname}:${eureka.instance.secure-port}/ctx/info
    home-page-url: https://${eureka.instance.hostname}:${eureka.instance.secure-port}/ctx

最新更新