certbot 是整个免费 HTTPS 证书体系(Let’s Encrypt)的核心官方客户端。
简单来说,它就是一个命令行工具,用来自动帮你申请、验证、安装、续期 Let’s Encrypt 免费证书。
Certbot 主要帮助你完成以下事情:
| 功能 | 说明 |
|---|---|
| ✅ 自动申请证书 | 向 Let’s Encrypt 服务器发送请求并验证你控制的域名 |
| ✅ 自动验证域名 | 用 HTTP 或 DNS 方式证明域名归你所有 |
| ✅ 自动配置 Web 服务器 | 可自动为 Apache / Nginx 写入 SSL 配置(也可不用) |
| ✅ 自动续期证书 | Let’s Encrypt 证书 90 天有效,Certbot 会自动续期 |
| ✅ 可单独生成证书 | 不改动现有配置,只生成证书文件(certonly 模式) |
它的来源
由 Electronic Frontier Foundation(EFF) 维护
是 Let’s Encrypt 官方推荐的客户端
适用于 Linux、Windows、macOS
官网: https://certbot.eff.org/
常见用法
| 场景 | 命令 | 说明 |
|---|---|---|
| 自动配置 Nginx | certbot --nginx -d example.com |
自动配置 HTTPS |
| 仅生成证书 | certbot certonly --standalone -d example.com |
不改 Apache |
| 使用现有网站目录验证 | certbot certonly --webroot -w /var/www/html -d example.com |
不停服务 |
| 测试续期 | certbot renew --dry-run |
检查自动续期是否成功 |
生成的证书存放路径
默认:/etc/letsencrypt/live/你的域名/
cert.pem — 域名证书
privkey.pem — 私钥
chain.pem — 中间证书
fullchain.pem — 完整证书链(web 服务器常用)
自动续期
Certbot 安装时通常会自动创建一个定时任务(systemd timer 或 cron):
-
每天检查一次证书是否接近过期
-
自动续期后可选执行 reload Apache/Nginx 命令
certbot renew –quiet && systemctl reload httpd