跳到主要内容
cPanel

TrustAsia(亚洲诚信)SSL 证书 cPanel 安装部署教程:398 天有效期、证书链与排错实战

问题背景与根因:cPanel 装完证书为何仍报证书链错误

TrustAsia(亚洲诚信)证书由 DigiCert 授权根签发,信任链与国际品牌一致,cPanel 部署本身不复杂,但实际故障多集中在“证书链”和“私钥匹配”两处。cPanel 的 SSL/TLS → Manage SSL Sites 要求 PEM 三件套:叶子证书 CRT、私钥 KEY、中间证书 CA Bundle。很多教程只让上传 .crt,浏览器因 AIA 补链看起来正常,而 curl、Java、微信小程序不会自动补链,于是报证书链不完整。

第二个根因是有效期与续期。公有 TLS 证书最长有效期 398 天,Let’s Encrypt 为 90 天;TrustAsia 付费证书签发时也受 398 天上限约束。续期后如果只替换文件而没有 reload Apache,443 端口仍返回旧证书。第三个根因是 SNI/域名绑定:cPanel 按域名写入虚拟主机,SAN 不包含 www 或子域时会报主机名不匹配。

先做三条基线检查:

openssl x509 -in example.com.crt -noout -subject -issuer -dates -ext subjectAltName
openssl x509 -noout -modulus -in example.com.crt | openssl md5
openssl rsa -noout -modulus -in example.com.key | openssl md5

两条 modulus 的 MD5 必须一致;ECDSA 证书没有 modulus,改用公钥比对(后文给出)。如果 issuer 不是 DigiCert 相关根/中间,或 notAfter 与签发日期间隔超过 398 天,先回到签发环节核对,不要继续在 cPanel 里反复重装。

准备证书文件:PEM 三件套、fullchain 与 398 天有效期核对

在 TrustAsia 控制台下载“cPanel / Apache”格式压缩包,解压后通常得到 example.com.crt、example.com.key、cabundle.crt。cPanel 只认 PEM:CRT 以 —–BEGIN CERTIFICATE—– 开头,KEY 以 —–BEGIN PRIVATE KEY—– 或 —–BEGIN RSA PRIVATE KEY—– 开头,CA Bundle 是中间证书拼接。不要上传 .pfx/.p12,也不要将私钥贴进 CRT 字段。

合并 fullchain 便于 Apache 2.4.8+ 使用:

cat example.com.crt cabundle.crt > fullchain.pem
openssl verify -CAfile cabundle.crt -untrusted cabundle.crt example.com.crt

期望输出 example.com.crt: OK。若报 unable to get local issuer certificate,说明 cabundle 缺少签发该证书的中间证书,或顺序错误。用系统根库再验一次:

openssl verify -CAfile /etc/ssl/certs/ca-certificates.crt -untrusted cabundle.crt example.com.crt
openssl x509 -in example.com.crt -noout -dates -checkend 2592000

-checkend 2592000 检查 30 天内是否过期,返回 0 表示未过期。再核对 SAN 是否同时包含 example.com 与 www.example.com:

openssl x509 -in example.com.crt -noout -ext subjectAltName
openssl pkey -in example.com.key -noout -check
chmod 600 example.com.key

私钥权限保持 600,属主为 cPanel 账户。若使用 ECDSA 证书,用下面两组命令比对公钥 MD5,而不是 modulus:

openssl x509 -pubkey -noout -in example.com.crt | openssl md5
openssl pkey -pubout -in example.com.key | openssl md5

完整实操步骤:在 cPanel 安装 TrustAsia 付费证书

登录 cPanel,进入 SSL/TLS → Manage SSL Sites。在 Domain 下拉框选择要部署的域名;Browse Certificate 上传 example.com.crt;Private Key 粘贴 example.com.key 全文;Certificate Authority Bundle 粘贴 cabundle.crt 全文。三个字段必须对应同一张证书,点击 Install。安装成功后 cPanel 会把证书写入该域名的 Apache SSL 虚拟主机,并在 SSL/TLS Status 显示有效。

随后进入 Domains,确认目标域名的 Force HTTPS Redirect 已开启;如果站点使用 WordPress,还要在后台把站点地址改为 https,避免登录后跳回 http。付费证书不要依赖 AutoSSL 自动续期:SSL/TLS Status → Run AutoSSL 只对 AutoSSL 管理的域名签发免费 DV,不会替你续期 TrustAsia 付费证书;可在证书到期前手动替换,避免证书失效后 AutoSSL 签发 DV 覆盖配置。

有 WHM root 权限时可用 API 批量安装:

whmapi1 installssl domain=example.com crt="$(cat example.com.crt)" key="$(cat example.com.key)" cabundle="$(cat cabundle.crt)"
/usr/local/cpanel/bin/rebuild_http_conf
/scripts/restartsrv_httpd
apachectl -S | grep -A2 example.com
httpd -t

apachectl -S 用于确认 443 虚拟主机指向正确配置文件;httpd -t 必须返回 Syntax OK。若 cPanel 报 The certificate is not valid for the domain,优先检查 SAN 与域名是否完全一致;报 Certificate does not match private key,回到上一节做 modulus/公钥比对。安装后不要直接改 /etc/apache2/conf/httpd.conf,cPanel 重建配置会覆盖;应使用 EA4 的 userdata include。

配置示例:EA4 Apache 虚拟主机、强制 HTTPS 与 HSTS

cPanel 使用 EA4 时,推荐把自定义 SSL 配置放到用户级 include,而不是改主配置。创建目录并写入:

mkdir -p /etc/apache2/conf.d/userdata/ssl/2_4/USER/example.com
vi /etc/apache2/conf.d/userdata/ssl/2_4/USER/example.com/ssl.conf

配置内容:

<VirtualHost *:443>
    ServerName example.com
    ServerAlias www.example.com
    DocumentRoot /home/USER/public_html
    SSLEngine on
    SSLCertificateFile /home/USER/ssl/example.com.crt
    SSLCertificateKeyFile /home/USER/ssl/example.com.key
    SSLCertificateChainFile /home/USER/ssl/cabundle.crt
    # Apache 2.4.8+ 也可改用 fullchain:
    # SSLCertificateFile /home/USER/ssl/fullchain.pem
    Header always set Strict-Transport-Security "max-age=31536000; includeSubDomains"
    <Directory /home/USER/public_html>
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

<VirtualHost *:80>
    ServerName example.com
    Redirect permanent / https://example.com/
</VirtualHost>

如果使用 SSLCertificateFile 指向 fullchain.pem,就不要再写 SSLCertificateChainFile,避免重复。HSTS 首次上线建议先用 max-age=300 观察,确认全站 HTTPS 与子域都可用后再加到 31536000。混合内容用 CSP 兜底:

Header always set Content-Security-Policy "upgrade-insecure-requests"

应用配置并验证:

httpd -t
/scripts/restartsrv_httpd
curl -I http://example.com
curl -I https://example.com

第一条 curl 应返回 301 且 Location 为 https;第二条返回 200 或业务状态码。若 301 跳到 https 后仍提示不安全,检查页面内 http:// 图片、脚本、表单,或 CDN 回源是否仍为 HTTP。

证书链与私钥匹配:本地校验命令与输出判读

证书链问题不要靠浏览器判断。先用本地 verify 判断 cabundle 是否完整:

openssl verify -CAfile cabundle.crt -untrusted cabundle.crt example.com.crt
openssl crl2pkcs7 -nocrl -certfile cabundle.crt | openssl pkcs7 -print_certs -noout

第一条返回 OK 才说明叶子证书能由该中间包接到可信根。第二条列出 cabundle 中每张证书的 subject 和 issuer,检查是否存在“叶子 issuer = 中间 subject”的对应关系。常见错误是把根证书和中间证书顺序颠倒,或 cabundle 里只有根没有中间。

私钥匹配用 modulus(RSA)或公钥(ECDSA):

openssl x509 -noout -modulus -in example.com.crt | openssl md5
openssl rsa -noout -modulus -in example.com.key | openssl md5
openssl x509 -pubkey -noout -in example.com.crt | openssl md5
openssl pkey -pubout -in example.com.key | openssl md5

两组输出必须分别一致。远程抓取实际返回的链:

openssl s_client -connect example.com:443 -servername example.com -showcerts </dev/null 2>/dev/null | openssl x509 -noout -subject -issuer -dates
echo | openssl s_client -connect example.com:443 -servername example.com -showcerts 2>/dev/null | grep -c 'BEGIN CERTIFICATE'

第二条计数若为 1,说明服务器只发送了叶子证书,curl/Java 很可能报 unable to get local issuer certificate;正常应为 2 或 3(叶子 + 中间,必要时含根)。还要核对 notAfter 是否已更新,避免“文件换了但服务没 reload”。

对比表格:AutoSSL、TrustAsia DV/OV 与三种部署方式

选择方案时先把“自动续期”和“证书链完整性”分开看。cPanel AutoSSL 适合免费 DV 和测试站,默认 90 天自动续期;TrustAsia 付费 DV/OV 适合需要中文审核、人民币计价和 DigiCert 信任链的业务站,签发有效期受 398 天上限约束。下表给出常见组合:

方案 验证方式 有效期 信任链 cPanel 安装 适用场景
cPanel AutoSSL(Let’s Encrypt/Sectigo DV) 域名验证 90 天,自动续期 各 CA 根 SSL/TLS Status → Run AutoSSL 测试站、内部站、预算优先
TrustAsia DV 域名验证 不超过 398 天 DigiCert 授权根 Manage SSL Sites 上传三件套 企业官网、API 域名
TrustAsia OV 组织验证 + 域名验证 不超过 398 天 DigiCert 授权根 同上,需提交单位资料 电商、金融、招投标

部署方式对比:cPanel UI 最直观,适合单域名;WHM API 适合批量,命令为 whmapi1 installssl;EA4 include 适合需要 HSTS、CSP、反代等自定义配置的站点。无论哪种方式,CA Bundle 都不能省。价格与折扣以证书购买页实时信息为准,不要按旧文章里的“一年期”描述采购,实际证书 notAfter 会受 398 天规则限制。

常见错误排查:真实报错、原因与修复命令

下面按真实报错归类。先看 curl:

curl: (60) SSL certificate problem: unable to get local issuer certificate

原因是服务器未发送中间证书,或客户端信任库没有对应根。修复:在 cPanel 的 CA Bundle 填入 cabundle.crt,或让 Apache 使用 fullchain.pem;用 openssl verify 确认返回 OK。

NET::ERR_CERT_COMMON_NAME_INVALID
curl: (60) SSL: no alternative certificate subject name matches target host name

证书 SAN 不包含访问域名。检查 openssl x509 -ext subjectAltName,重新签发包含裸域、www 或子域的证书;CDN 场景还要检查回源 Host 与 SNI。

AH02565: Certificate and PrivateKey ... do not match

Apache 启动报私钥不匹配。用 modulus 或公钥 MD5 比对,确认上传的是同一张证书对应的 key;不要把 CSR 当证书,也不要把旧私钥配新证书。

PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

Java 客户端不补链。先修服务器 fullchain;若仍报错,把 DigiCert 根或中间证书导入 Java 的 cacerts:keytool -importcert -alias trustasia-ca -file cabundle.crt -keystore $JAVA_HOME/lib/security/cacerts。微信小程序报 ssl hand shake error 也优先查链完整性与 TLS 版本。

SSL_ERROR_RX_RECORD_TOO_LONG

443 端口返回的不是 TLS,常见于 Nginx/Apache 监听错端口、CDN 回源协议写成 HTTP、或防火墙端口映射错误。用 curl -vI https://example.com 看握手阶段,用 ss -lntp | grep 443 核对监听。

续期后浏览器仍显示旧证书:执行 /scripts/restartsrv_httpd,再用 openssl s_client 查看 notAfter;若前面有 CDN,还要在 CDN 控制台更新证书。混合内容报 Mixed Content 时,把资源改成 https 或加 CSP upgrade-insecure-requests。

效果验证:cPanel 状态、curl、openssl 与 SSL Labs 评级

先在 cPanel 的 SSL/TLS Status 确认目标域名显示绿色有效标记,并核对到期日。再用 curl 验证证书校验结果:

curl -vI https://example.com 2>&1 | grep -E 'SSL certificate verify|subject:|issuer:'
curl -I https://example.com

期望出现 SSL certificate verify ok,HTTP 返回 200 或 301。接着用 openssl 做严格校验:

openssl s_client -connect example.com:443 -servername example.com -verify_return_error </dev/null
echo | openssl s_client -servername example.com -connect example.com:443 2>/dev/null | openssl x509 -noout -enddate
openssl s_client -connect example.com:443 -servername example.com -tls1_2 </dev/null | grep 'Protocol'

第一条应输出 Verify return code: 0 (ok);第二条核对 notAfter 是否为新证书;第三条确认 TLS 1.2 可用。TLS 1.3 可将参数换成 -tls1_3。再查 HSTS 与跳转:

curl -sI https://example.com | grep -i strict-transport-security
curl -sI http://example.com | grep -i '^location'

最后用 SSL Labs API 评级:

curl -s 'https://api.ssllabs.com/api/v3/analyze?host=example.com&publish=off&all=done' | jq -r '.endpoints[0].grade'

期望 A 或 A+。若为 B,检查是否仍启用 TLS 1.0/1.1、弱套件、缺少 HSTS;若为 T,检查是否只支持 TLS 1.3 而客户端不兼容。验证完成后,用微信开发者工具、Java 客户端各复测一次,确认不再出现证书链报错。

常见问题

上传 PEM 三件套:叶子证书 .crt、私钥 .key、CA Bundle(中间证书)。在 SSL/TLS → Manage SSL Sites 中分别填入;若 Apache 2.4.8+ 使用 fullchain.pem,则不要再重复配置 ChainFile。上传后务必用 openssl verify 验证链完整,并确认私钥与证书匹配。

浏览器会通过 AIA 自动补中间证书,curl、Java、小程序通常不会。服务器只发叶子证书时就会报 unable to get local issuer certificate 或 PKIX path building failed。修复是安装完整 CA Bundle 或使用 fullchain,并用 openssl s_client -showcerts 确认返回 2-3 张证书。

不能。AutoSSL 只管理其自动签发的免费 DV 证书,不会替你续期付费 TrustAsia 证书。付费证书到期前需手动替换 CRT、KEY、CA Bundle 并重启 Apache;若证书失效,AutoSSL 可能签发 DV 覆盖配置。建议在到期前 30 天处理。

替换 cPanel 中的证书、私钥和 CA Bundle 后,执行 /usr/local/cpanel/bin/rebuild_http_conf 与 /scripts/restartsrv_httpd,再用 openssl s_client 核对 notAfter。若前面有 CDN,还要在 CDN 控制台更新证书,否则用户仍看到旧证书。

RSA 证书分别执行 openssl x509 -noout -modulus -in cert.crt | openssl md5 和 openssl rsa -noout -modulus -in key.key | openssl md5,两值必须一致;ECDSA 用 openssl x509 -pubkey 与 openssl pkey -pubout 比对 MD5。不一致就重新下载对应私钥,不要混用旧 key。

在 cPanel → Domains 查看 Force HTTPS Redirect 是否为开启状态;再用 curl -I http://example.com 检查是否返回 301 且 Location 为 https。WordPress 站点还要把站点地址改为 https,并检查页面混合内容,避免跳转后仍加载 http 资源。

内容审核

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