帮助

通过 certbot 使用 Auto SSL(Linux、nginx 和 Apache)

Auto SSL 是一项订阅服务:您的服务器通过 ACME 协议自行获取并续期 Sectigo DV 证书。本文介绍在 Linux(Ubuntu、Debian、AlmaLinux)上通过 certbot 为 nginx 和 Apache 进行配置。如果您更喜欢 acme.sh,请参阅单独的指南

在哪里获取密钥

  1. 登录个人中心 1host.kz/bill,打开"Auto SSL (Sectigo ACME)"服务。如果尚未订阅,请在 Auto SSL 页面下单。
  2. 点击"Configure Now"(配置)。在"Single Domains"字段中填写域名(example.kzwww.example.kz 视为同一域名)。*.example.kz 请使用"Wildcard Domains"字段——这是单独的项目。
  3. 5–30 秒后,服务卡片中会显示四个值:ACME account IDEAB MAC IDEAB MAC keyServer URL

在下面的命令中:Server URLhttps://acme.sectigo.com/v2/DV(所有客户相同),YOUR_EAB_KID 为 EAB MAC ID 字段的值,YOUR_EAB_HMAC_KEY 为 EAB MAC key 字段的值。密钥如同密码,请勿公开。证书只会为已加入订阅的域名签发。

需要准备

  • 拥有 root 或 sudo 权限的服务器。
  • 域名(及 www)的 A 记录指向该服务器。
  • 80 端口对外开放——CA 通过它验证域名(http-01)。
  • certbot 1.3 或更新版本:EAB 支持从该版本开始。我们在 certbot 4.0 上进行了测试。

安装 certbot

Ubuntu / Debian:

sudo apt update
sudo apt install certbot python3-certbot-nginx     # 用于 nginx
sudo apt install certbot python3-certbot-apache    # 用于 Apache

AlmaLinux / Rocky / CentOS Stream:

sudo dnf install epel-release
sudo dnf install certbot python3-certbot-nginx python3-certbot-apache

如果仓库中的版本过旧,请通过 snap 安装最新版:sudo snap install --classic certbot。检查版本:certbot --version

签发证书

无需单独注册账户:首次运行时 certbot 会根据 EAB 密钥自动创建。我们验证过的 webroot 方式(Web 服务器提供 /.well-known/acme-challenge/ 的目录):

sudo mkdir -p /var/www/acme
sudo certbot certonly --webroot -w /var/www/acme -d example.kz -d www.example.kz \
  --server https://acme.sectigo.com/v2/DV \
  --eab-kid YOUR_EAB_KID --eab-hmac-key YOUR_EAB_HMAC_KEY \
  --email [email protected] --agree-tos --no-eff-email

使用 webroot 时,nginx 的 80 端口配置中必须包含:

location /.well-known/acme-challenge/ {
    root /var/www/acme;
}

如果希望 certbot 自动修改 Web 服务器配置并接入证书,请将 certonly --webroot -w /var/www/acme 替换为插件:

# nginx
sudo certbot --nginx -d example.kz -d www.example.kz \
  --server https://acme.sectigo.com/v2/DV \
  --eab-kid YOUR_EAB_KID --eab-hmac-key YOUR_EAB_HMAC_KEY \
  --email [email protected] --agree-tos --no-eff-email

# Apache
sudo certbot --apache -d example.kz -d www.example.kz \
  --server https://acme.sectigo.com/v2/DV \
  --eab-kid YOUR_EAB_KID --eab-hmac-key YOUR_EAB_HMAC_KEY \
  --email [email protected] --agree-tos --no-eff-email

签发大约需要 20 秒。账户保存在 /etc/letsencrypt/accounts/acme.sectigo.com/,因此后续签发和续期无需再指定 EAB 密钥——只需 --server。要将订阅中的多个域名放入同一张证书,用 -d 依次列出即可;每个域名都必须指向该服务器。

证书文件与接入

文件位于 /etc/letsencrypt/live/example.kz/fullchain.pem(含证书链的证书)和 privkey.pem(私钥)。如果使用 certonly 签发,请在配置中手动指定:

# nginx
ssl_certificate     /etc/letsencrypt/live/example.kz/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.kz/privkey.pem;

# Apache
SSLCertificateFile    /etc/letsencrypt/live/example.kz/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/example.kz/privkey.pem

为了让 Web 服务器在续期后加载新证书,请添加一次重载钩子(certbot 会将其记录到续期配置中):

sudo certbot renew --deploy-hook "systemctl reload nginx"

同样的文件也可用于邮件服务器、控制面板或其他服务——服务器许可证不限数量。

常见错误

  • 验证时 Connection refused / Timeout——80 端口被防火墙拦截或域名未指向服务器。用 dig +short example.kzcurl -I http://example.kz/.well-known/acme-challenge/test 检查。
  • 授权错误或 CA 拒绝订单——域名不在订阅中。请在个人中心添加("Add domain"),必要时追加购买("Buy more domains")。
  • unrecognized arguments: --eab-kid——certbot 版本过旧。请通过 snap 更新。
  • 订阅未激活——在续费账单支付之前不会签发新证书(账单在到期前 14 天开出)。已签发的证书在到期前继续有效。

检查与续期

确认网站使用的是 Sectigo 证书并查看有效期:

echo | openssl s_client -connect example.kz:443 -servername example.kz 2>/dev/null \
  | openssl x509 -noout -issuer -dates
sudo certbot certificates

issuer 行中应包含 O = Sectigo Limited。续期由 certbot 的标准定时器完成:每天运行两次,更新剩余有效期不足 30 天的证书。检查定时器是否启用以及续期是否无错误:

systemctl list-timers | grep certbot
sudo certbot renew --dry-run

如果使用 cron 而不是 systemd,任务位于 /etc/cron.d/certbot。无需其他操作:只要订阅有效,证书就会自动续期。如遇问题,请在个人中心向 ONEHOST 技术支持提交工单——我们全天候协助配置。

如有任何疑问,请联系我们