certbot开启亚马逊EC2主机https

国内那么多云主机运营商, 你为何要买国外的主机呢, 你肯定在干些见不得人的勾当..

开玩笑了, 说不定你在闷声发大财也说不准.

之前有说过可以利用certbot申请免费的证书,给站点开启https
传送门

certbot在亚马逊的主机无法顺利执行,不过可以通过手动修改源代码的方式,这样certbot就可以完成任务了.

用vim 打开 certbot

//搜索找到这一行
elif [ -f /etc/redhat-release ]; then

//然后替换成如下:
elif [ -f /etc/redhat-release ] || grep 'cpe:.*:amazon_linux:2' /etc/os-release > /dev/null 2>&1; then

//保存退出收工

这样就可以利用 certbot --nginx 一步到位了.

不过前提是 你的nginx 必须要安装在 /etc 目录下面,
假如不是这个目录的话, 你可以把你当前的nginx 安装目录的config 配置文件copy到/etc/nginx 下.没有就手动创建. 这样执行certbot --nginx之后 ,再把他生成的最终配置文件copy到当前nginx目录下,然后nginx -s reload 重启即可

文中所说certbot 要修改的地方就是这里
https://github.com/certbot/certbot/blob/master/certbot-auto#L779
可以在github上查看

自动更新证书

//使用root用户
sudo -i

//增加定时任务
crontab -e

//每个月1号2点30分更新
30 2 1 * * /path/to/certbot-auto renew --pre-hook "service nginx stop" --post-hook "service nginx start"

//dry run
./path/to/certbot-auto renew --dry-run

猜你喜欢

转载自www.cnblogs.com/chuchur/p/10462323.html
EC2
今日推荐