You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

多域名SAN证书抛出‘unable to verify the first certificate’错误求助

解决自签名SAN证书的unable to verify the first certificate错误

首先,这个报错通常和证书不被信任、证书链不完整或者证书已过期有关,结合你提供的证书信息,咱们一步步排查解决:

1. 先紧急排查:证书是否过期?

从你给出的证书详情看,Not After : Mar 23 22:15:10 2019 GMT——这个证书早就过期了!过期证书一定会触发验证失败,这是首要需要解决的问题。

你可以用命令再次确认有效期:

openssl x509 -in trustedCertificates.pem -noout -dates

如果确实过期,得重新生成有效期内的自签名SAN证书,生成时记得指定需要的多域名(比如通过openssl配置文件添加subjectAltName = DNS:domain1.example,DNS:domain2.example,或者用命令行参数-addext "subjectAltName=DNS:...")。

2. 确认SAN扩展配置是否正确

既然是多域名SAN证书,要确保证书里确实包含了你要使用的所有域名:

openssl x509 -in trustedCertificates.pem -noout -ext subjectAltName

如果输出里没有你需要的域名,说明生成证书时没配置SAN扩展,得重新生成符合要求的证书。

3. 将自签名证书加入信任存储

自签名证书默认不会被系统或应用信任,必须手动添加到信任列表:

系统级信任(推荐,所有应用通用)

  • Linux(Debian/Ubuntu):
    1. 复制证书到系统CA目录:
      sudo cp trustedCertificates.pem /usr/local/share/ca-certificates/trustedCertificates.crt
      
    2. 更新CA缓存:
      sudo update-ca-certificates
      
  • macOS:
    1. 双击trustedCertificates.pem文件,在钥匙串访问中打开
    2. 找到该证书,右键选择「显示简介」
    3. 在「信任」栏目下,将「使用此证书时」设置为「始终信任」
  • Windows:
    1. 双击证书文件,点击「安装证书」
    2. 选择「本地计算机」,下一步
    3. 选择「将所有证书放入下列存储」,点击「浏览」,选择「受信任的根证书颁发机构」
    4. 完成安装后重启相关应用

应用级信任(针对特定应用,比如Node.js、Python)

  • Node.js:
    通过环境变量指定额外CA证书:
    NODE_EXTRA_CA_CERTS=./trustedCertificates.pem node your-app.js
    
    或者在代码中手动指定CA:
    const https = require('https');
    const fs = require('fs');
    
    const options = {
      ca: fs.readFileSync('./trustedCertificates.pem')
    };
    
    https.get('https://your-domain.example', options, (res) => {
      // 处理响应逻辑
    });
    
  • Python(requests库):
    在请求时直接指定证书文件:
    import requests
    
    response = requests.get('https://your-domain.example', verify='./trustedCertificates.pem')
    

4. 验证修复效果

用curl测试是否还存在验证错误:

curl -v --cacert trustedCertificates.pem https://your-domain.example

如果输出中显示SSL certificate verify ok.,说明问题已经解决。

内容的提问来源于stack exchange,提问作者annunarcist

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 04:05:23