range

If there were you, the world would be just right

Certbot 的官方网站 https://certbot.eff.org/
当前工作目录为 /root

获取certbot

wget https://dl.eff.org/certbot-auto
chmod a+x certbot-auto

停止nginx

service nginx stop

生成证书(如果后期生成报错,先删除原有certbot-auto,按第一步重新下载certbot即可)

使用-d追加多个域名,使用时请将邮箱换成自己的邮箱

 ./certbot-auto certonly --standalone --email 1396833166@qq.com -d api.gowanme.com -d pay.gowanme.com -d box.gowanme.com

查看生成的证书

ls /etc/letsencrypt/live/

在nginx配置证书

#证书位置
ssl_certificate /etc/letsencrypt/live/cdw.me/fullchain.pem;
# 私钥位置
ssl_certificate_key /etc/letsencrypt/live/cdw.me/privkey.pem;

启动nginx

service nginx start

编写更新脚本update_ssl.sh

#!/bin/bash

# 停止nginx
/sbin/service nginx stop

# 续签
# --force-renew 强制更新
/root/certbot-auto renew --force-renew

# 启动nginx
/sbin/service nginx start

chmod a+x update_ssl.sh

定时任务自动更新https证书

//crontab定时任务自动更新证书
0 4 1 */2 * /root/update_ssl.sh >/root/crontab.log 2>&1

Let’s Encrypt 生成的免费证书为3个月时间,但是我们可以无限次续签证书

本文参考:
https://yq.aliyun.com/articles/138272