跳到主要内容
ssl证书按装

DV/OV/EV SSL证书选型、有效期新规与Nginx HTTPS配置实战

DV/OV/EV SSL证书选型、有效期新规与Nginx HTTPS配置实战 — DV/OV/EV SSL证书选型、有效期新规与Nginx HTTPS配置实战

1. 问题背景与根因:HTTP 明文、证书类型混淆与有效期新规

SSL 证书是口语叫法,现代 HTTPS 实际运行在 TLS 1.2/1.3 上。网站只启用 HTTP 时,登录口令、Cookie、支付回调和 API Token 都以明文传输,链路上可被监听、篡改或劫持。2014 年 Google 将 HTTPS 纳入排名信号,2017 年起 Chrome 对 HTTP 页面标记“不安全”,HTTP/2、微信小程序和 App Store 应用也普遍要求 HTTPS。因此问题通常不是“要不要证书”,而是证书类型选错、域名覆盖不全、证书链不完整、续期靠手工。

另一个高频根因是有效期认知过时。公开信任 TLS 证书单张最长有效期已从 398 天收紧:自 2026-03-15 起为 200 天,2027-03-15 起为 100 天,2029-03-15 起为 47 天;Let’s Encrypt 仍为 90 天。仍按 398 天做年度续期计划,容易出现过期告警。先做基线检查:

curl -I http://example.com
openssl version -a
printf '' | openssl s_client -connect example.com:443 -servername example.com 2>/dev/null | openssl x509 -noout -subject -issuer -dates -ext subjectAltName

若第一条返回 200 而不是 301/308,说明没有强制 HTTPS;若证书 SAN 不含 www 或 API 子域,浏览器会报域名不匹配;若 issuer 后缺少中间证书,Java、curl 等客户端会报无法获取本地颁发者。EV 证书的“绿色地址栏”也已过时,主流浏览器不再普遍展示,选型时应看验证强度和合规需求,而不是承诺绿色地址栏。

2. 证书选型与签发前准备:DV、OV、EV 与 CSR

DV 只验证域名控制权,适合个人站、测试环境、API 和 Let’s Encrypt 自动化;OV 需验证企业真实身份,适合企业官网、政企和对外业务;EV 审核最严,需组织、法律和电话核验,适合金融、强合规或品牌信任场景,但不要以绿色地址栏作为采购承诺。签发前先确认 DNS 的 A/AAAA 记录指向正确服务器,80/443 端口对 CA 验证可达,并列出所有需要覆盖的域名:example.com、www.example.com、api.example.com 等。

用 OpenSSL 生成私钥和 CSR,SAN 必须一次写全。以下命令要求 OpenSSL 1.1.1 及以上:

openssl version -a
openssl req -new -newkey rsa:2048 -nodes -keyout example.com.key -out example.com.csr -subj '/C=CN/ST=Beijing/L=Beijing/O=Example Ltd/CN=example.com' -addext 'subjectAltName=DNS:example.com,DNS:www.example.com'
openssl req -in example.com.csr -noout -text | grep -A1 'Subject Alternative Name'

CSR 里 CN 只写一个主域名,其余域名放 SAN;不要再用只含 CN 的旧证书。OV/EV 需在 CA 平台提交营业执照、组织名称、电话回拨等材料,签发周期通常 1-3 个工作日或 3-7 个工作日;DV 可分钟级完成。公开信任证书新签发最长 200 天,Let’s Encrypt 为 90 天,因此必须把续期自动化纳入交付,而不是一年一续。

3. 完整实操步骤:Nginx + Let’s Encrypt 自动签发

以 Ubuntu/Debian 和 Nginx 为例,先放行 80/443,确认域名解析,再安装 Certbot。Certbot 的 nginx 插件会自动改配置、申请证书并加 301 跳转。首次申请建议加 –staging 测试,确认无误后去掉。命令如下:

sudo apt update
sudo apt install -y certbot python3-certbot-nginx
sudo certbot --nginx -d example.com -d www.example.com --agree-tos -m ops@example.com --redirect
sudo certbot renew --dry-run
sudo certbot certificates

CentOS/RHEL 可把前两条换成 sudo dnf install -y certbot python3-certbot-nginx。如果使用 OV/EV,不能靠 Certbot 自动完成组织核验,需要按 CA 要求提交材料,拿到证书后把 fullchain.pem 和 privkey.pem 部署到服务器。Let’s Encrypt 证书有效期 90 天,certbot.timer 通常每天检查两次并自动续期;执行 renew –dry-run 无报错才算自动化可用。生产环境不要用 –staging 证书对外服务,否则浏览器会报证书不受信任。若 80 端口被占用,可改用 –nginx 或 –webroot,不要直接停生产服务。最后确认 systemctl list-timers | grep certbot 能看到下一次执行时间。

4. 配置示例:Nginx 与 Apache 关键参数

Nginx 必须同时配置 80 跳转和 443 证书链。fullchain.pem 包含服务器证书与中间证书,privkey.pem 是私钥;只配 cert.pem 容易导致部分客户端报 unable to get local issuer certificate。Nginx 1.25.1 及以上建议用 http2 on,旧版本可写 listen 443 ssl http2。示例:

server {
    listen 80;
    server_name example.com www.example.com;
    return 301 https://$host$request_uri;
}
server {
    listen 443 ssl;
    http2 on;
    server_name example.com www.example.com;
    ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
    ssl_protocols TLSv1.2 TLSv1.3;
    ssl_ciphers HIGH:!aNULL:!MD5;
    ssl_session_cache shared:SSL:10m;
    ssl_session_timeout 1d;
    add_header Strict-Transport-Security 'max-age=31536000; includeSubDomains' always;
}

Apache 需启用 ssl 和 headers 模块,关键片段如下:

<VirtualHost *:80>
    ServerName example.com
    Redirect permanent / https://example.com/
</VirtualHost>
<VirtualHost *:443>
    SSLEngine on
    SSLCertificateFile /etc/letsencrypt/live/example.com/fullchain.pem
    SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem
    SSLProtocol -all +TLSv1.2 +TLSv1.3
    Header always set Strict-Transport-Security 'max-age=31536000; includeSubDomains'
</VirtualHost>

Tomcat 在 server.xml 的 SSLHostConfig 中配置 certificateFile 与 certificateKeyFile,IIS 导入含完整链的 PFX 后绑定 443;共同原则是链完整、私钥匹配、关闭 TLS 1.0/1.1。修改后先 nginx -t 或 apachectl configtest,再 reload。HSTS 首次上线建议先用 max-age=300 观察,确认全站 HTTPS 后再加到一年;否则回退 HTTP 会造成访问困难。

5. 对比表格:DV、OV、EV 与有效期基线

三类证书的核心差异在验证深度和证书详情,而不是加密强度。DV、OV、EV 都可以使用 RSA 2048/ECDSA P-256 和 TLS 1.2/1.3。选型时按业务场景:个人站和 API 优先 DV;企业官网、政企、招投标材料优先 OV;金融、强合规再考虑 EV。主流浏览器已不再普遍展示 EV 绿色地址栏,EV 的价值在严格核验、组织信息和合规证明。

类型 验证内容 典型签发 浏览器展示 适用场景
DV SSL 域名控制权,DNS/HTTP/文件验证 分钟级 锁标与 HTTPS,无组织名 个人站、API、测试、Let’s Encrypt
OV SSL 域名控制权 + 企业真实身份 1-3 个工作日 锁标,证书详情含组织 企业官网、政企、对外业务
EV SSL 严格组织、法律、电话核验 3-7 个工作日 不再普遍显示绿色地址栏 金融、强合规、品牌信任

有效期基线必须写进运维制度:公开信任 TLS 证书自 2026-03-15 起单张最长 200 天,2027-03-15 起 100 天,2029-03-15 起 47 天;398 天是旧规则,不再适用于新签发公开证书。Let’s Encrypt 仍为 90 天,且续期应完全自动化。采购时不要只看价格,要确认是否含中间链、是否支持 SAN 多域名、是否提供到期提醒和自动续期方案。

6. 常见错误排查(含真实报错)

排障顺序是:先看浏览器/客户端报错,再用 openssl 查 SAN、证书链和有效期,最后查 Nginx/Apache 配置与端口。以下错误在交付中最常见:

  • NET::ERR_CERT_COMMON_NAME_INVALID 或 x509: certificate is valid for a.example.com, not b.example.com:SAN 漏域名。重新签发时加 -addext ‘subjectAltName=DNS:example.com,DNS:www.example.com’,用 openssl x509 -in fullchain.pem -noout -ext subjectAltName 核对。
  • curl: (60) SSL certificate problem: unable to get local issuer certificate:中间链缺失。Nginx 配 fullchain.pem,不要配 cert.pem;用 printf ” | openssl s_client -connect example.com:443 -servername example.com -showcerts 检查证书链。
  • nginx: [emerg] cannot load certificate … BIO_new_file() failed … No such file or directory:路径错误或权限不足。执行 ls -l /etc/letsencrypt/live/example.com/ 和 nginx -t,确认 ssl_certificate 指向 fullchain.pem,私钥可被 Nginx 读取。
  • Problem binding to port 80: Could not bind to IPv4 or IPv6.:80 被占用。执行 ss -lntp | grep ‘:80’ 找进程;Nginx 场景用 certbot –nginx,独立模式需先停占用服务,或改用 –webroot。
  • too many certificates already issued for exact set of domains:触发 Let’s Encrypt 限流。测试用 –dry-run 或 –staging,生产等待限流窗口恢复,不要反复重试。

另外,若报 SSL routines::ee key too small,说明私钥强度不足,改用 RSA 2048 或 ECDSA P-256;若报 SSL_ERROR_BAD_CERT_DOMAIN,优先检查访问域名是否在 SAN 中,而不是先改 TLS 版本。

7. 效果验证与持续监控

配置完成后不要只看浏览器锁标,要做命令行验证。HTTP 必须 301/308 到 HTTPS,HTTPS 返回 200,证书 SAN、issuer、有效期正确,TLS 1.0/1.1 关闭。推荐命令:

curl -I http://example.com
curl -I https://example.com
printf '' | openssl s_client -connect example.com:443 -servername example.com -tls1_2 2>/dev/null | openssl x509 -noout -subject -issuer -dates -ext subjectAltName
nmap --script ssl-enum-ciphers -p 443 example.com
certbot certificates
systemctl list-timers | grep certbot

openssl 输出中重点看 notBefore/notAfter 是否覆盖当前时间,subjectAltName 是否包含所有业务域名,issuer 链是否完整。nmap 结果不应出现 TLSv1.0 和 TLSv1.1;若出现,检查 ssl_protocols 是否被旧配置覆盖。Certbot 的 certbot certificates 应显示证书路径和到期日,systemctl list-timers 应显示 certbot.timer 下一次执行时间。

持续监控建议加一条到期检查:printf ” | openssl s_client -connect example.com:443 -servername example.com 2>/dev/null | openssl x509 -checkend 2592000 -noout;返回非 0 表示 30 天内到期,应触发告警。再用 SSL Labs 或 testssl.sh 做外部评分,目标为 A/A+、无 TLS 1.0/1.1、HSTS 生效、80 端口全量跳转。最后用不同网络和 Java/curl 客户端各测一次,避免只在本机浏览器正常。

常见问题

DV 只验证域名控制权,适合个人站、API 和 Let’s Encrypt;OV 验证企业真实身份,适合企业官网和政企;EV 审核最严但主流浏览器已不普遍显示绿色地址栏,金融或强合规场景按需选择。公开信任证书新签发最长有效期自 2026-03-15 起为 200 天。


CA/B 论坛已缩短公开信任 TLS 证书有效期:2026-03-15 起单张最长 200 天,2027-03-15 起 100 天,2029-03-15 起 47 天;398 天是旧基线。Let’s Encrypt 仍为 90 天,建议用 certbot 自动续期并监控到期。


配 fullchain.pem。fullchain 包含服务器证书和中间证书,能避免 curl: (60) unable to get local issuer certificate;私钥配 privkey.pem。只配 cert.pem 时浏览器可能正常,但 Java、curl 等客户端常因缺中间链报错。


用 curl -I http://example.com 看是否 301,curl -I https://example.com 看是否 200;再用 openssl s_client -connect example.com:443 -servername example.com 检查证书链、SAN 和有效期;最后用 SSL Labs 或 nmap ssl-enum-ciphers 确认只启用 TLS 1.2/1.3。


先运行 ss -lntp | grep ‘:80’ 找占用进程;Nginx 场景用 certbot –nginx,独立模式需停掉占用 80 的服务,也可改用 –webroot。测试用 –dry-run 或 –staging,避免触发 too many certificates already issued 限流。


主流 Chrome、Firefox、Safari 已不再普遍展示 EV 绿色地址栏,只显示锁标和证书详情中的组织信息。EV 的价值主要在严格身份核验、合规和品牌信任,不应以绿色地址栏作为采购承诺。

内容审核

长期从事 SSL/TLS 证书部署与 HTTPS 运维,负责本站证书选型、安装配置与故障排查内容的编写与审核。