我在spring boot中有几个服务,可以用eureka服务器自行注册 .
这些服务在http上工作正常 . 但是,当我使用https时,由于SSL验证,客户端注册失败 .
如何在DiscoveryClient中添加自签名jks文件以信任https证书?
编辑
我的application.yml文件
spring:
application:
name: docker-prototype-user-profile
server:
port: 8301
eureka:
client:
registerWithEureka: true
fetchRegistry: true
serviceUrl:
defaultZone: https://localhost:8761/eureka/
instance:
hostname: localhost
我的application.properties文件
server.ssl.key-store=classpath:keypair.jks
server.ssl.key-store-password=123456
server.ssl.key-password=123456
这里的jks文件与eureka服务器中的相同 . 我在所有服务中使用相同的密钥进行https . 由于jks文件包含公钥和私钥,所以这里用于2个目的 . 第一是为此服务的https提供私钥 . 我要在eureka发现客户端使用此作为证书 .
keytool -genkeypair \
-keystore keypair.jks \
-dname "CN=OLEKSIYS-W3T, OU=Sun Java System Application Server, O=Sun Microsystems, L=Santa Clara, ST=California, C=US" \
-keypass 123456 \
-storepass 123456 \
-keyalg RSA \
-keysize 2048 \
-alias default \
-ext SAN=DNS:localhost,DNS:docker-prototype,DNS:docker-prototype-authentication,DNS:docker-prototype-eureka-server,DNS:docker-prototype-post-management,DNS:docker-prototype-secure-service,DNS:docker-prototype-user-management,DNS:docker-prototype-user-profile,DNS:docker-prototype-zuul-gateway \
-validity 9999
keypair是使用上面的命令生成的