如何在 Ubuntu 上自动续订 Let's Encrypt certbot 证书

新: 我们的新文章如何在 30 秒内安装自动化 certbot/LetsEncrypt 续订介绍了使用 systemd 和自动化安装程序的更新流程。

在 Ubuntu 上,你可以轻松设置一个每日任务来尝试续订即将过期的 Let’s Encrypt 证书。

创建 /etc/cron.daily/renewcerts

renewcerts
#!/bin/bash
certbot renew
service nginx reload

之后,sudo chmod a+x /etc/cron.daily/renewcerts

现在你应该验证脚本是否会实际运行:

run_parts_test.sh
run-parts --test -v /etc/cron.daily

应该打印(除其他行外)此行:

run_parts_output.txt
/etc/cron.daily/renewcerts

重要: 你仍然需要每 1-2 个月手动运行 certbot renew 以检查是否有任何可能阻止证书续订的错误。

注意: 由于脚本调用 service nginx reload,你需要确保如果你编辑 nginx 配置文件,它们不会长时间处于损坏状态。编辑后使用 sudo nginx -t 检查错误。还要注意,如果你进行 nginx 配置更改,脚本可能会无意中将它们应用到你的生产 HTTP/HTTPS 服务器!


Check out similar posts by category: Cryptography, Linux