Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用特定端口在eureka中注册spring boot https应用程序_Spring_Spring Boot_Https_Netflix Eureka_Spring Cloud Netflix - Fatal编程技术网

使用特定端口在eureka中注册spring boot https应用程序

使用特定端口在eureka中注册spring boot https应用程序,spring,spring-boot,https,netflix-eureka,spring-cloud-netflix,Spring,Spring Boot,Https,Netflix Eureka,Spring Cloud Netflix,我正在尝试注册一个仅通过https可用的应用程序。我的配置不正确,eureka仪表板中显示的链接不正确。我尝试了一些配置,但无法获得正确的效果,即在Eureka中使用仪表板链接 我的基本配置 server: port: 9999 context-path: /ctx ssl: key-store: classpath:keystore.jks key-store-password: 'kspass' key-password: 'kpass' keyA

我正在尝试注册一个仅通过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
我尝试了以下版本的健康/状态/主页URL:

  • 无端口的绝对URL

    示例:运行状况检查url:https://${eureka.hostname}/ctx/health

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

  • 使用${server.port}替换的绝对URL

    示例:运行状况检查url:https://${eureka.hostname}:${server.port}/ctx/health)

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

  • 相对URL

    示例:运行状况检查url路径:/ctx/health

    结果: http://localhost:9999/ctx/info,没有https


  • 最后一个与我的期望非常接近,但是没有https,我终于找到了问题的解决方案。不确定这是否是最好的,因为据我所知,它不适用于随机端口,即server.port=0。在这种情况下,eureka使用端口0注册应用程序,并且在仪表板上存在与端口的链接,该链接不会转发到正确的位置,这不是预期的行为

    我们必须使用配置${eureka.instance.secure port}的eureka部分,而不是使用与当前应用程序相关的${server.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
    

    我自己还没有测试过,但这可能会有所帮助:,请注意,他们使用的是securePortEnabled,而不是SecurePort-enabled@ShmulikAsafi不,没用。在这种情况下,属性名约定并不重要,因为spring boot使用的是轻松绑定器/属性解析器。非常有用,谢谢。请注意,
    eureka.instance.hostname
    在您的配置中非常重要。