certbot开启亚马逊EC2主机https

邱秋 • 2019年01月17日 • 阅读:1087 • 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

我,秦始皇,打钱!

相关文章

禅境花园小程序

关注前沿技术开发.