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

解决 Nginx 报警 ssl_stapling ignored, issuer certificate not found

分析 Nginx 开启 OCSP Stapling 报 issuer certificate not found 诱因,详解 fullchain 完整证书链与 resolver 配置。

问题现象

在 Nginx 中配置开启 OCSP Stapling(OCSP 封套)优化 HTTPS 握手后,执行配置测试输出警告:

nginx: [warn] "ssl_stapling" ignored, issuer certificate not found for certificate "/etc/nginx/ssl/cert.pem"

虽然 Nginx 仍可运行,但客户端无法在 TLS 握手时直接获取 OCSP 吊销凭证,首次连接延迟增大。

触发根因

  1. 仅配置了叶子证书,缺少中间 CA 证书(Intermediate Certificate):ssl_certificate 指令指向的文件只包含站点单域名证书,没有包含签发机构的中间证书链。Nginx 无法验证签发者的签名,因此无法向 CA 服务器请求 OCSP 凭证。
  2. Nginx 缺少 DNS 解析器(resolver):OCSP Stapling 需要 Nginx 后台进程向 CA 的 OCSP URL 发送 HTTP 查询,若未配置 resolver,Nginx 无法解析 CA 的域名。

诊断排查步骤

检查证书文件包含的证书块数量:

grep "BEGIN CERTIFICATE" /etc/nginx/ssl/cert.pem | wc -l

若仅为 1,说明不是完整的证书链(Fullchain 至少包含 2~3 个证书块)。

解决方案

方案一:使用包含完整证书链的 fullchain.pem

确保 ssl_certificate 指向拼接了中间证书的完整链文件:

server {
    listen 443 ssl http2;
    server_name example.com;

    # 必须使用 fullchain.pem 而非单一的 cert.pem
    ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;

    # 开启 OCSP Stapling
    ssl_stapling on;
    ssl_stapling_verify on;
    ssl_trusted_certificate /etc/letsencrypt/live/example.com/fullchain.pem;

    # 核心:必须配置 DNS 解析器以便 Nginx 查询 OCSP 结果
    resolver 223.5.5.5 8.8.8.8 valid=300s;
    resolver_timeout 5s;
}

验证方法

测试配置语法:

sudo nginx -t

输出显示:

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

不再产生任何 ssl_stapling ignored 警告,OCSP 封套功能平稳就绪。