用 SSL/TLS 保护网站已不再是可选项,而是绝对要求。但短期有效期与合规需求,使手动安装难以扩展,尤其当 397 天证书正走向 47 天周期。Sectigo 提供 ACME 自动化,但它并不原生集成进 cPanel,这意味着系统管理员不得不走手动路线。好消息是:借助 Certbot,你依然可以自动化 Sectigo SSL 证书的签发与续期。本指南涵盖从安装、配置、通配符支持到自动化的全部内容,让你能在 cPanel/WHM 服务器上毫无障碍地管理 Sectigo SSL。设置是一次性的,配置完成后,Certbot 会处理自动续期。

前置条件

开始之前,请确认以下各项。跳过它们是 SSL 安装失败的头号原因:

  • 对 cPanel 或 WHM 服务器的 Root SSH 访问;
  • 在 cPanel 中配置好的域名,且正确的 DNS A 与 AAAA 记录指向服务器;
  • 防火墙中开放 80 和 443 端口(ACME 挑战所需);
  • 来自你 Sectigo 订单详情的 EAB 凭据(Key ID 和 HMAC key)。

若不确定端口是否开放,可从另一台机器使用 nmap 之类的工具:

nmap -p 80,443 yourdomain.com

若端口关闭,Certbot 验证会立即失败。

第 1 步——安装 Certbot

Certbot 是我们用来与 Sectigo 的 ACME 服务器通信的客户端。虽然 cPanel 默认不自带它,安装却很直接。

选项 A——通过 Snap 安装(推荐)

sudo yum install snapd -y
sudo systemctl enable --now snapd.socket
sudo ln -s /var/lib/snapd/snap /snap
sudo snap install core
sudo snap refresh core
sudo snap install --classic certbot
sudo ln -s /snap/bin/certbot /usr/bin/certbot

选项 B——通过 Yum 安装(基础,但可能过时)

sudo yum install epel-release -y
sudo yum install certbot -y

这用于测试尚可,但 Yum 包往往较旧。过时的 Certbot 版本可能在 Sectigo 更新其 ACME 端点时失败。最佳实践是尽可能使用 Snap,它保证你运行最新的 Certbot,减少兼容性问题。

第 2(A) 步——申请 Sectigo SSL(标准域名)

Certbot 安装好后,即可申请证书。Sectigo 要求 EAB 凭据(购买 Sectigo ACME 证书时提供)。

Apache 示例

sudo certbot --apache \
--non-interactive \
--agree-tos \
--email admin@example.com \
--server https://acme.sectigo.com/v2/DV \
--eab-kid YOUR_EAB_KID \
--eab-hmac-key YOUR_EAB_HMAC_KEY \
--domain example.com \
--cert-name example-cert

Nginx 示例

sudo certbot --nginx \
--non-interactive \
--agree-tos \
--email admin@example.com \
--server https://acme.sectigo.com/v2/DV \
--eab-kid YOUR_EAB_KID \
--eab-hmac-key YOUR_EAB_HMAC_KEY \
--domain example.com \
--cert-name example-cert

若出现 urn:ietf:params:acme:error:badEABCredentials 错误,说明你的 EAB Key ID 或 HMAC Key 有误。请仔细从 Sectigo 面板复制。

把证书集成进 cPanel/WHM

Certbot 把签发的证书放在:

/etc/letsencrypt/live/example.com/fullchain.pem
/etc/letsencrypt/live/example.com/privkey.pem

有两种方式把它引入 cPanel。

方法 1——WHM GUI

  • 以 root 登录 WHM;
  • 进入 SSL/TLS -> Install an SSL Certificate on a Domain;
  • 粘贴对应值:证书(CRT)为 fullchain.pem,私钥(KEY)为 privkey.pem,CA Bundle 通常在 fullchain.pem 内(或使用 chain.pem)。

方法 2——CLI(用于自动化)

/usr/local/cpanel/bin/installssl domain example.com \
cert /etc/letsencrypt/live/example.com/fullchain.pem \
key /etc/letsencrypt/live/example.com/privkey.pem \
cabundle /etc/letsencrypt/live/example.com/chain.pem

cPanel 环境中的自动续期

这是许多管理员忽略的环节。cPanel 不会自动续期 Sectigo 证书。如果你止步于此,你的 SSL 会在几天后过期。

  • 测试续期:sudo certbot renew --dry-run——若失败,现在就修复,不要等到续期日;
  • 添加 cron 任务:sudo crontab -e;
  • 然后插入:0 */12 * * * certbot renew --quiet --deploy-hook "/usr/local/cpanel/bin/installssl domain example.com cert /etc/letsencrypt/live/example.com/fullchain.pem key /etc/letsencrypt/live/example.com/privkey.pem cabundle /etc/letsencrypt/live/example.com/chain.pem"

这每天运行两次。若证书已续期,--deploy-hook 会把它直接推入 WHM。

第 2(B) 步——用 Certbot 申请 Sectigo 通配符证书

通配符证书(*.example.com)需要 DNS-01 验证,因为 HTTP-01 验证不适用于通配符。你有两个选项:

  • 自动 DNS(推荐)——对受支持的提供商(Cloudflare、Route53、DigitalOcean 等)使用 Certbot DNS 插件;
  • 手动 DNS——每次手动创建 TXT 记录,或使用 Lexicon 脚本。

使用 Certbot DNS 插件(以 Cloudflare 为例)

安装插件:

sudo snap install certbot-dns-cloudflare

创建凭据文件:

mkdir -p ~/.secrets/certbot
nano ~/.secrets/certbot/cloudflare.ini

内容:

dns_cloudflare_api_token = YOUR_CLOUDFLARE_API_TOKEN

用以下命令加固文件权限:

chmod 600 ~/.secrets/certbot/cloudflare.ini

申请通配符:

sudo certbot certonly \
--dns-cloudflare \
--dns-cloudflare-credentials ~/.secrets/certbot/cloudflare.ini \
--server https://acme.sectigo.com/v2/DV \
--eab-kid YOUR_EAB_KID \
--eab-hmac-key YOUR_EAB_HMAC_KEY \
--email admin@example.com \
--agree-tos \
--cert-name example-wildcard \
-d "*.example.com" -d example.com

检查你的 DNS 提供商是否受支持

Certbot 为许多 DNS 提供商提供插件,例如:AWS Route53(certbot-dns-route53)、Google Cloud DNS(certbot-dns-google)、DigitalOcean(certbot-dns-digitalocean)、Cloudflare(certbot-dns-cloudflare)、GoDaddy 社区版(certbot-dns-godaddy)、Hetzner(certbot-dns-hetzner)、OVH(certbot-dns-ovh)、Linode(certbot-dns-linode)。完整插件列表见 https://certbot.eff.org/docs/using.html#dns-plugins 。若你的提供商在列,安装相应插件即可。

示例:AWS Route53

sudo snap install certbot-dns-route53
sudo certbot certonly \
--dns-route53 \
--server https://acme.sectigo.com/v2/DV \
--eab-kid YOUR_EAB_KID \
--eab-hmac-key YOUR_EAB_HMAC_KEY \
--email admin@example.com \
--agree-tos \
--cert-name example-wildcard \
-d "*.example.com" -d example.com

示例:DigitalOcean

sudo snap install certbot-dns-digitalocean
mkdir -p ~/.secrets/certbot
nano ~/.secrets/certbot/digitalocean.ini

内容:

dns_digitalocean_token = YOUR_DO_API_TOKEN

加固权限:

chmod 600 ~/.secrets/certbot/digitalocean.ini
sudo certbot certonly \
--dns-digitalocean \
--dns-digitalocean-credentials ~/.secrets/certbot/digitalocean.ini \
--server https://acme.sectigo.com/v2/DV \
--eab-kid YOUR_EAB_KID \
--eab-hmac-key YOUR_EAB_HMAC_KEY \
--email admin@example.com \
--agree-tos \
--cert-name example-wildcard \
-d "*.example.com" -d example.com

若无官方插件——使用 Lexicon

若你的 DNS 提供商没有官方 Certbot 插件,可以使用通用 DNS 管理库 Lexicon。

pip install dns-lexicon

创建 Hook 脚本:

auth.sh:

#!/bin/bash
lexicon godaddy create "$CERTBOT_DOMAIN" TXT \
--auth-key "YOUR_GODADDY_KEY" \
--auth-secret "YOUR_GODADDY_SECRET" \
--name "_acme-challenge.$CERTBOT_DOMAIN" \
--content "$CERTBOT_VALIDATION"

cleanup.sh:

#!/bin/bash
lexicon godaddy delete "$CERTBOT_DOMAIN" TXT \
--auth-key "YOUR_GODADDY_KEY" \
--auth-secret "YOUR_GODADDY_SECRET" \
--name "_acme-challenge.$CERTBOT_DOMAIN" \
--content "$CERTBOT_VALIDATION"

赋予可执行权限:

chmod +x auth.sh cleanup.sh

用 Lexicon 申请通配符:

sudo certbot certonly \
--manual \
--preferred-challenges dns \
--manual-auth-hook /path/to/auth.sh \
--manual-cleanup-hook /path/to/cleanup.sh \
--server https://acme.sectigo.com/v2/DV \
--eab-kid YOUR_EAB_KID \
--eab-hmac-key YOUR_EAB_HMAC_KEY \
--email admin@example.com \
--agree-tos \
--cert-name example-wildcard \
-d "*.example.com" -d example.com

签发后,证书存储在 /etc/letsencrypt/live/example.com/,在 cPanel 或 WHM 中安装:

/usr/local/cpanel/bin/installssl domain example.com \
cert /etc/letsencrypt/live/example-wildcard/fullchain.pem \
key /etc/letsencrypt/live/example-wildcard/privkey.pem \
cabundle /etc/letsencrypt/live/example-wildcard/chain.pem

自动化续期

Certbot 自动处理续期。对于 DNS 挑战(如 Lexicon),请确保你的 auth.sh 和 cleanup.sh 脚本始终可访问。为强制执行自动化,添加 cron 任务:

0 */12 * * * certbot renew --quiet --deploy-hook "/usr/local/cpanel/bin/installssl domain example.com cert /etc/letsencrypt/live/example-wildcard/fullchain.pem key /etc/letsencrypt/live/example-wildcard/privkey.pem cabundle /etc/letsencrypt/live/example-wildcard/chain.pem"

最佳实践

  • 时常检查续期日志:Certbot 在自动化续期上做得很好,但事情仍可能出错——DNS 变更、防火墙更新或过期 API 令牌都可能在无预警下中断续期。偶尔浏览续期日志,确保证书按预期刷新。这是能避免大坑的小步骤;
  • 为预发和生产使用不同名称:测试新证书时,不要复用同一个 --cert-name。在试验时很容易意外覆盖你的线上证书。给预发和生产证书清晰、独立的名称,让你明确知道哪些可安全测试;
  • 验证你的配置:安装证书后,从外部双重确认。网上有许多工具能显示外界如何看到你的站点,在访客遇到错误前发现弱密码、链问题或不完整的安装;
  • 锁定 API 密钥与凭据:如果你使用 DNS API 或 Lexicon 脚本,请像密码一样对待这些令牌。把它们存储在受限文件(chmod 600)中,使服务器上其他人无法访问。泄露的 API 密钥可能让他人修改你的 DNS 记录。

结语

在 cPanel 或 WHM 上安装 Sectigo ACME 证书,虽不像使用 AutoSSL 那样无缝,但有了 Certbot,过程基本实现了自动化。你将获得适用于合规和企业需求、且直接集成进 cPanel 的可靠 Sectigo SSL 覆盖,并带有自动续期。标准和通配符域名都受支持,让你一次覆盖多种用例。通过设置正确的 cron 任务并留意日志,你消除了证书在不知不觉中期的风险。前期投入时间配置,意味着更少的手动干预、更少的证书续期操作,以及长期更安全、无烦恼的托管环境。

通过 Certbot 在 cPanel/WHM 上实现 Sectigo SSL 自动化

一次性设置、免维护续期、借助 ACME 自动化实现持续安全。不再有手动安装或过期之忧。如需获取 ACME SSL 证书,请通过正规渠道申请。

相关文章:

  • 什么是 ACME 协议及其工作原理:完整指南
  • ACME 如何变革现代企业的 SSL 自动化
  • 如何使用 Certbot 在 Apache 与 Nginx 上安装 ACME SSL 证书
  • 如何使用 Win-ACME 与 EAB 凭据在 IIS 上安装 SSL 证书