DEBUG.WIKI
阿里云;从建站到云上业务;云服务器 · 数据库 · 对象存储;查看产品 →
PanstarCloud:部署应用,接入 AI,云服务器与 AI 网关
IPPeak:从目标地区访问网页,住宅代理、SEO 监测、广告验证

解决 Postman/cURL 报错 SSL certificate problem: unable to get local issuer certificate

使用 cURL、Postman 或在代码中通过 SDK 请求 HTTPS API 接口时抛出 SSL certificate problem: unable to get local issuer certificate。本文详解 CA 根证书链缺失、企业代理自签名拦截及更新 ca-certificates 的修复手段。

问题现象

在终端使用 curl 请求 HTTPS 接口或在 Python/Node.js 客户端发包时,握手被阻断:

curl: (60) SSL certificate problem: unable to get local issuer certificate
More details here: https://curl.se/docs/sslcerts.html

curl failed to verify the legitimacy of the server and therefore could not
establish a secure connection to it.

在 Postman 中则显示 Error: unable to get local issuer certificate。

触发根因

  1. 操作系统缺少受信任的 CA 根证书包:本地 ca-certificates 过旧或未安装,无法验证目标域名证书签发机构(Issuer)的公钥真伪。
  2. 服务端未下发中间证书链(Incomplete Certificate Chain):目标服务器的 Web 服务器(Nginx/Apache)仅配置了叶子证书(Domain Certificate),缺少中间 CA 证书(Intermediate CA),导致客户端找不到上级颁发者。
  3. 企业内网代理或杀毒软件深度报文检测(DPI):在公司网络环境下,流量经过了企业安全网关(如 Zscaler、Fortinet),网关动态解密并用自签名根证书重新加密,而开发者本地电脑未信任该内网根证书。

诊断排查步骤

1. 查看目标服务端的证书链颁发完整度

openssl s_client -connect api.example.com:443 -servername api.example.com

查看输出的 Certificate chain:

  • 若仅有 0 s:... i:... 且返回 Verify return code: 21 (unable to verify the first certificate),说明服务端缺少中间证书。

2. 检查本地 curl 使用的证书路径

curl-config --ca

解决方案

方案一:更新操作系统基础 CA 证书库

在 Linux 服务器或开发机上更新全球受信任根证书:

# Ubuntu / Debian
sudo apt update && sudo apt install -y ca-certificates
sudo update-ca-certificates

# RHEL / Rocky / CentOS
sudo yum install -y ca-certificates
sudo update-ca-trust

方案二:向系统受信任库导入企业自签名/私有 CA 证书

如果是企业内网环境拦截,获取公司的根证书文件(如 company_root_ca.crt):

# Ubuntu / Debian
sudo cp company_root_ca.crt /usr/local/share/ca-certificates/
sudo update-ca-certificates

# RHEL / CentOS
sudo cp company_root_ca.crt /etc/pki/ca-trust/source/anchors/
sudo update-ca-trust extract

方案三:临时在 cURL / Postman 中指定或放行(仅限本地排错)

在 cURL 命令行显式指定 CA 证书路径:

curl --cacert /path/to/custom-ca.pem https://api.example.com

如果是在内网个人沙箱开发环境临时调试接口,可使用 -k(--insecure)跳过校验:

curl -k https://api.example.com

在 Postman 设置中:Settings -> General -> SSL certificate verification -> OFF。

警告:生产代码与自动化脚本严禁关闭 SSL 验证,否则会导致中间人攻击(MITM)窃取凭证。

验证方法

再次执行 cURL 请求:

curl -I https://api.example.com

能够直接返回 HTTP/2 200 或相应的 API 响应报文,不再有证书信任链阻断报错,说明修复生效。