title: "certbot nginx SSL 证书管理" date: 2021-09-29T00:37:08+07:00
现在很多站的 HTTPS 使用的是 Lets Encrypt 颁发的免费证书,证书 90 天过期,自动续期基本往往都会出现问题导致不能真正的自动续期。甚至后来的手动续期也会有各种各样的问题。比如
Your system is not supported by certbot-auto anymore.
我推荐到 Let's Encrypt 的官方网站上参看指导方案解决。
打开网站https://certbot.eff.org/lets-encrypt/snap-nginx,从页面中找到 My HTTP website is running () on () 这句话,从下拉列表中选择自己的 web 服务器类型和操作系统或这使用的管理工具。
本篇文章就是这个页面的中文翻译,对应 My HTTP website is running (nginx) on (pip)。我的 server 是 Debian9,考虑到 pip 这个解决方案可能有更好的通用性。
$ sudo apt updte
$ sudo apt install python3 python3-venv libaugeas0
$ sudo apt remove certbot
$ sudo python3 -m venv ./certbot
$ cd certbot
$ source bin/activate
$ pip install --upgrade pip
$ pip installl certbot certbot-nginx
$ ln -s ./bin/certbot ./certbot
一步到位执行
$ sudo certbot --nginx
shell
$ sudo certbot certonly --nginx
$ echo "0 0,12 * * * root /opt/certbot/bin/python -c 'import random; import time; time.sleep(random.random() * 3600)' && certbot renew -q" | sudo tee -a /etc/crontab > /dev/null
纯测试可运行
$ sudo certbot renew --dry-run
在 3 中的虚拟环境中执行
$ sudo pip3 --upgrade certbot certbot-nginx
出错的话删掉虚拟环境重装。