title: "certbot nginx SSL 证书管理" date: 2021-09-29T00:37:08+07:00
现在很多站的 HTTPS 使用的是 Let's Encrypt 颁发的免费证书,证书 90 天过期,自动续期基本往往都会出现问题导致不能真正的自动续期。甚至后来的手动续期也会有各种各样的问题。比如:
Your system is not supported by certbot-auto anymore.
我推荐到 Let's Encrypt 的官方网站上参看指导方案解决。
打开网站https://certbot.eff.org/instructions,从页面中找到 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
$ sudo certbot certonly --nginx
设置自动续期 在 /etc/crontab 中追加
$ 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
出错的话删掉虚拟环境重装。