Spring Boot启用SSL时遇ERR_SSL_VERSION_OR_CIPHER_MISMATCH错误如何解决?
问题描述
尝试为Spring Boot应用配置Let's Encrypt证书启用SSL时,遇到ERR_SSL_VERSION_OR_CIPHER_MISMATCH错误,操作步骤如下:
- 导出Let's Encrypt生成的有效
.crt证书 - 使用以下命令导入到.p12密钥库:
keytool -import -alias springboot -file myCertificate.crt -keystore springboot.p12 -storepass password
- 将密钥库放入项目
src/main/resources目录 - 在
application.yml中添加配置:
ssl: key-store: classpath:springboot.p12 key-store-password: password
- 启动服务器访问
https://localhost:8080/时,Chrome提示ERR_SSL_VERSION_OR_CIPHER_MISMATCH
补充说明:
- 生产环境测试时无此错误,但出现
ERR_CONNECTION_TIMED_OUT - 使用自签名证书无问题,但需使用Let's Encrypt有效证书
解决建议
1. 确保密钥库包含完整证书链+私钥
你当前用keytool -import仅导入了单独的证书文件,而Spring Boot的SSL密钥库需要同时包含证书对应私钥和完整信任链(Let's Encrypt根证书+中间证书),否则无法完成SSL握手。正确操作:
- 从Let's Encrypt获取对应私钥文件(比如
privkey.pem)和完整证书链文件(包含你的域名证书+中间证书,通常命名为fullchain.pem) - 用
openssl将私钥和证书链打包为PKCS12格式密钥库:openssl pkcs12 -export -in fullchain.pem -inkey privkey.pem -out springboot.p12 -name springboot -password pass:password
2. 补全Spring Boot SSL配置项
你的application.yml缺少关键配置参数,需补充完整:
server: ssl: key-store: classpath:springboot.p12 key-store-password: password key-store-type: PKCS12 key-alias: springboot key-password: password # 若私钥密码与密钥库密码一致,可省略
明确指定key-store-type为PKCS12,避免Spring Boot自动识别出错;同时显式声明key-alias,确保加载正确的证书条目。
3. 修正本地测试的域名匹配问题
Let's Encrypt证书绑定特定域名,用localhost访问会触发域名不匹配的SSL验证错误。本地测试可:
- 修改本地
hosts文件,将证书绑定的域名指向127.0.0.1 - 用证书对应的域名访问(比如
https://your-domain.com:8080),而非localhost
关于生产环境的ERR_CONNECTION_TIMED_OUT
此错误与SSL配置无关,大概率是:
- 生产服务器的SSL端口(默认8443,若你自定义则对应端口)未在防火墙/安全组中开放
- 应用未正确监听SSL端口,需检查配置中是否指定了
server.port=8443 - 网络路由问题导致请求无法到达服务器
内容的提问来源于stack exchange,提问作者Victor Soares
相关产品推荐
相关产品推荐

