ssl-guides 2026-12-02 ⏱ 1 min read

用 Certbot 获取免费 SSL 证书

用 Certbot 获取免费 SSL 证书
快速回答:要用 Certbot 获取免费 SSL 证书,先安装它,然后 Nginx 运行 sudo certbot --nginx -d example.com -d www.example.com,Apache 使用 --apache。Certbot 会验证域名、安装证书并安排续期。没有 Web 服务器插件?用 webroot 或 standalone 方式配合 certonly 命令。

用 Certbot 获取免费 SSL 证书之前

  • 域名的 DNS 必须指向服务器(DNS 查询可查看解析结果)。
  • HTTP 验证要求 80 端口可从互联网访问。
  • 如果设置了 CAA 记录,必须允许 Let's Encrypt。可用CAA 检测工具检查。

用 Certbot 获取免费 SSL 证书:选择方式

方式命令适用场景
Nginx 插件certbot --nginxNginx 正在运行,希望自动修改配置
Apache 插件certbot --apacheApache 正在运行,同样方便
Webrootcertbot certonly --webroot想自己编辑配置并保持服务器运行
Standalonecertbot certonly --standalone还没有 Web 服务器,或用于邮件服务器等非 Web 服务
DNScertbot certonly --dns-...通配符证书,或 80 端口无法访问的服务器

示例

# Nginx with automatic config
sudo certbot --nginx -d example.com -d www.example.com

# Webroot, no config changes
sudo certbot certonly --webroot -w /var/www/html -d example.com -d www.example.com

# Standalone, needs port 80 free
sudo certbot certonly --standalone -d example.com

文件会出现在 /etc/letsencrypt/live/example.com/ 中。让服务器指向 fullchain.pem 和 privkey.pem。不要把这些文件复制到别处,因为 "live" 里的条目是符号链接,Certbot 会在续期时更新它们。

用 Certbot 续期免费 SSL 证书

软件包通常会安装 systemd 定时器或 cron 条目。用试运行检查:

sudo certbot renew --dry-run
sudo certbot certificates

Let's Encrypt 证书目前有效期为 90 天,从 10 February 2027 起为 64 天,从 16 February 2028 起为 45 天(Let's Encrypt 公告)。Certbot 在剩余寿命不足三分之一时续期:90 天证书剩 30 天,64 天证书约剩 21 天,45 天证书剩 15 天(Certbot 文档)。关于部署钩子、定时器和监控,请阅读自动续期免费 SSL 证书和无停机续期 SSL。

常见错误

信息原因解决办法
Timeout during connect防火墙封了 80 端口开放 80 端口
Unauthorized / 404 on the challengewebroot 路径错误或存在重写规则检查 -w 路径,并允许访问 /.well-known/
DNS problem: NXDOMAIN域名尚不存在创建 DNS 记录
Too many certificates触发速率限制等待,并用 --dry-run 测试
Address already in useStandalone 无法绑定 80 端口停止 Web 服务器,或改用 webroot

验证

安装后,运行SSL 检测工具确认证书链和到期日期;如果启用了跳转,再运行HTTPS 跳转检测工具。完整的服务器教程见VPS SSL 指南。

相关阅读:修复 Certbot 续期错误、什么是 ACME 协议以及不用 cPanel 安装免费 SSL。

常见问题

Certbot 是使用 Let's Encrypt 的唯一方式吗?

不是。ACME 客户端有很多,托管面板通常也自带。Certbot 是最常见的参考工具。

能为 IP 地址或 localhost 获取证书吗?

Let's Encrypt 只能通过 shortlived 配置文件签发 IP 地址证书,有效期约 160 小时(Let's Encrypt 配置文件)。常规流程需要真实域名,localhost 无法获得公开证书。

如何吊销或删除证书?

用 certbot revoke --cert-path ... 吊销,用 certbot delete 删除本地文件。

首次运行需要电子邮件地址吗?

Certbot 会要求填写一个地址作为账户联系方式。Let's Encrypt 已于 4 June 2025 停止发送到期提醒(Let's Encrypt 公告),所以这个地址不能替代到期告警。

🔒 Test Your Website SSL Certificate Now
Run Free SSL Check →

✅ Post-Installation Verification & SEO Checklist

After applying the steps above, run through this 5-point checklist to prevent browser warnings and protect your Google SEO rankings:

  • Verify full CA chain trust and TLS 1.3 support using our Live SSL Checker.
  • Scan for Mixed Content HTTP links and check HSTS/CSP headers on Security Headers Checker.
  • Enforce a permanent 301 HTTP-to-HTTPS redirect with our HTTPS Redirect Generator.
  • Confirm both root and www versions resolve cleanly to one canonical HTTPS URL.
  • Verify your HTTPS property and sitemap.xml inside Google Search Console and Bing Webmaster Tools.
Technically Reviewed by TryFreeSSL Security Team
Last updated: 2026-12-05
About Us →

免费 SSL 证书签发、在线 SSL 检测与 CSR 生成器

无需复杂服务器配置,60 秒快速获取 Let's Encrypt 与 Buypass 信任的 HTTPS 证书。

Related Articles

🤖 TryFreeSSL AI Assistant