今天发现我司网站HTTPS无法访问了。
之前用Lets encrypt做了免费的证书,有印象是90天需要续期,掐指一算,差不多了。
google了半天,看了一堆中、英文文章,看的云里雾里。
最后,还是去官方网站一行一行仔细阅读,终于拨开云雾见青山。
按照官方文档https://eff-certbot.readthedocs.io/en/stable/using.html#renewing-certificates,只需要执行certbot renew
命令即可。
因为,certbot
是运行在docker里的,没法直接执行命令。
再查了docker-compose的文档,找到了最终的答案:
docker-compose exec certbot certbot renew
注意第一个certbot是容器名。
执行完命令,进入到certbot/conf/live/mydomain.com
目录ls
一看,果然文件修改日期已经变为今天。
执行完,记得nginx要重新reload哦。
docker-compose exec web nginx -s reload
注意第一个nginx是容器名。
为了下次不再手动renew,用crontab建个定时任务吧。
cd /opt/data
vi renew.sh
docker-compose exec certbot certbot renew --post-hook "docker exec web nginx -s reload"
chmod +x renew.sh
crontab -e
具体cron配置如下:
# 每月1日、15日5点renew
0 5 1,15 * * /opt/data/renew.sh
通过以下命令查看日志:
tail -f /var/log/syslog | grep CRON