certboot 续订成功时自动重新加载 Nginx?

Cyr*_* N. 3 nginx lets-encrypt

每三个月,我的 Let's Encrypt 证书就会过期,我的客户会获得无效的 https 证书。

所以我最近放置了以下 cron 任务:

@weekly certbot renew --quiet && service nginx reload
Run Code Online (Sandbox Code Playgroud)

据我了解,当certbot renew成功更新证书时,它会返回成功状态(exit(0)),因此&&紧随其后,因此重新加载nginx。

是的,但它不起作用。我最近让我的服务器再次显示过期的证书,所以我肯定误解了一些东西,和/或我的 cron 任务不好。

你能告诉我路径吗?:)

Qua*_*tim 5

更好的方法是使用--renew-hook可以调用脚本的方法。也是--no-self-upgrade自动续订的好选择,此选项可防止续订期间的更新,这可能会破坏某些内容

cron记录可以

certbot renew --quiet --no-self-upgrade --renew-hook /path/to/hook.sh
Run Code Online (Sandbox Code Playgroud)

hook.sh

#!/bin/sh
set -e
nginx -t -q && nginx -s reload
exit 0
Run Code Online (Sandbox Code Playgroud)

仅当更新操作发生时才会调用此脚本,而不是每周都会调用

完整的解释位于手册页或文档中

  • `--renew-hook` 标志在最近版本的 certbot 中已被弃用。您应该将续订脚本移至 `/etc/letsencrypt/renewal-hooks/deploy/01-reload-nginx` - 请参阅 https://www.guyrutenberg.com/2017/01/01/lets-encrypt-reload-nginx -after-renewing-certificates/ 了解更多详细信息。 (2认同)