在Eureka中使用特定端口注册Spring Boot https应用程序 [英] Register spring boot https application in eureka with specific port
问题描述
我正在尝试注册仅可通过https使用的应用程序.我对正确的配置有疑问,并且在eureka的仪表板上显示的链接不正确.我已经尝试了一些配置,但无法获得正确的效果,即Eureka中的仪表板链接有效.
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.
我的基本配置.
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:
-
不带端口的绝对URL
Absolute URLs without port
例如:health-check-url:https://$ {eureka.hostname}/ctx/health
Example: health-check-url: https://${eureka.hostname}/ctx/health
结果:https://localhost/ctx/info
Result: https://localhost/ctx/info
替换$ {server.port}的绝对URL
Absolute URLs with ${server.port} replacement
例如:health-check-url:https://$ {eureka.hostname}:$ {server.port}/ctx/health)
Example: health-check-url: https://${eureka.hostname}:${server.port}/ctx/health)
结果:$ {server.port}未解析,仪表板中的URL为: https://localhost:$ {server.port}/ctx/info
Result: ${server.port} not resolved, url in dashboard is: https://localhost:${server.port}/ctx/info
相对网址
示例:health-check-url-path:/ctx/health
Example: health-check-url-path: /ctx/health
结果: http://localhost:9999/ctx/info,没有https.
Result: http://localhost:9999/ctx/info, no https.
最后一个与我的预期非常接近,但是没有没有https .
Last one is quite close to my expectations, but there is no https.
推荐答案
最后,我已经解决了我的问题.不确定它是否是最好的,因为据我所知,它不适用于随机端口,即server.port =0.在这种情况下,eureka使用端口0注册应用程序,并且在仪表板上存在与未转发端口的链接来纠正位置,这不是预期的行为.
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.
代替使用与当前应用程序相关的$ {server.port}占位符,我们必须使用eureka的$ {eureka.instance.secure-port}配置部分
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
这篇关于在Eureka中使用特定端口注册Spring Boot https应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!