Certbot可以配置为在证书过期之前自动更新证书。由于Let’s Encrypt SSL证书有效期时间为90天,所以建议您利用此功能。您可以通过运行以下命令来测试证书的自动续订:
1 | certbot --nginx certonly |
一些异常处理方法
1.找不到nginx插件
安装certbot-nginx插件
1 | pip install certbot-nginx |
2.找不到nginx
配置nginx环境变量
1 | vi /etc/profile |
添加一下配置
export NGINX_HOME=/usr/local/nginx
export PATH=$PATH:$NGINX_HOME/sbin
3.找不到nginx配置文件
复制配置文件到以上报错目录
1 | cp -r /usr/local/nginx/conf/* /etc/nginx/ |
再次测试
1 | certbot --nginx certonly |
如果以上正常工作,你可以通过添加运行以下操作的cron或systemd定时任务安排自动更新:
1 | certbot renew |
我们写一个自动执行脚本,建议每小时执行一次:
1 | crontab -e |
添加以下内容:
1 | 0 */6 * * * /usr/bin/certbot renew --quiet && /bin/systemctl reload nginx |