1. 程式人生 > >certbot開啟亞馬遜EC2主機https

certbot開啟亞馬遜EC2主機https

nta mas start gre -s dha post dry 你在

國內那麽多雲主機運營商, 你為何要買國外的主機呢, 你肯定在幹些見不得人的勾當..

開玩笑了, 說不定你在悶聲發大財也說不準.

之前有說過可以利用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

certbot開啟亞馬遜EC2主機https