使用特定端口在 eureka 中注册 spring 引导 https 应用程序
Register spring boot https application in eureka with specific port
我正在尝试注册一个只能通过 https 访问的应用程序。我在正确配置方面遇到问题,尤里卡仪表板中显示的链接不正确。我已经尝试了一些配置,但我无法获得正确的效果,即在 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
我尝试了以下版本的 health/status/home 网址:
没有端口的绝对 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。在那种情况下,尤里卡使用端口 0 注册应用程序,并且在仪表板上有 link端口不转发到正确的位置,这不是预期的行为。
我们必须使用 eureka 的配置部分 ${eureka.instance.secure-port} 而不是使用与当前应用程序相关的 ${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
我正在尝试注册一个只能通过 https 访问的应用程序。我在正确配置方面遇到问题,尤里卡仪表板中显示的链接不正确。我已经尝试了一些配置,但我无法获得正确的效果,即在 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
我尝试了以下版本的 health/status/home 网址:
没有端口的绝对 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。在那种情况下,尤里卡使用端口 0 注册应用程序,并且在仪表板上有 link端口不转发到正确的位置,这不是预期的行为。
我们必须使用 eureka 的配置部分 ${eureka.instance.secure-port} 而不是使用与当前应用程序相关的 ${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