Register spring boot https application in eureka with specific port

会有一股神秘感。 提交于 2019-12-24 07:14:16

问题


I am trying to register an application available through https only. I have problem with correct configuration and links displayed in eureka's dashboard are not correct. I have tried some configurations but I can't get the right effect i.e. working dashboard links in Eureka.

My base configuration.

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

I have tried following versions of health/status/home URLs:

  1. Absolute URLs without port

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

    Result: https://localhost/ctx/info

  2. Absolute URLs with ${server.port} replacement

    Example: health-check-url: https://${eureka.hostname}:${server.port}/ctx/health)

    Result: ${server.port} not resolved, url in dashboard is: https://localhost:${server.port}/ctx/info

  3. Relative URLs

    Example: health-check-url-path: /ctx/health

    Result: http://localhost:9999/ctx/info, no https.

Last one is quite close to my expectations, but there is no https.


回答1:


Finally I've got solution for my problem. Not sure it that's the best one because as far as I can see it doesn't work with random ports i.e. server.port = 0. In that case eureka registers application with port 0 and on dashboard there is link with port that does not forward to correct location and that's not expected behavior.

Instead of using ${server.port} placeholder that is related to current application we have to use eureka's part of configuration ${eureka.instance.secure-port} i.e.

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


来源:https://stackoverflow.com/questions/44804371/register-spring-boot-https-application-in-eureka-with-specific-port

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!