首页 > 解决方案 > Eureka Discovery Client 添加自签名证书

问题描述

我在 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提供私钥。第二,我想在尤里卡发现客户端中使用它作为证书。

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

使用上述命令生成密钥对

标签: javaspring-bootsslnetflix-eureka

解决方案


推荐阅读