工具 · 约 1 分钟阅读
宝塔面板下用 certbot 管理证书(亲测)
宝塔安装的 nginx 不在 /etc 下,certbot 直接跑会报错。加上 --nginx-server-root 指到宝塔的配置目录即可,文末附自动续签。
宝塔安装的 nginx 配置文件不在 /etc 下,直接运行 certbot 会报错。这里记录一下亲测通过的步骤。
1. 安装 certbot
yum install certbot python3-certbot-nginx -y
2. 检查 nginx 配置
nginx -t
3. 指定宝塔的 nginx 配置目录
宝塔的 nginx 配置目录通常在 /www/server/nginx/conf/:
certbot --nginx --nginx-server-root=/www/server/nginx/conf/
4. 按提示操作
- 填写使用的邮箱。
- 是否同意服务条款,选择
Y。 - 选择要配置的域名序号。
5. 重启 nginx
nginx -s reload
6. 配置自动续签
证书有效期是 90 天。为了避免手动续签,把续签任务加到 crontab:
crontab -e
写入:
0 0 1 * * certbot renew --quiet --renew-hook 'systemctl reload nginx' > /dev/null 2>&1
特别说明:方法来源于网络,本文为本人亲测整理后的版本。