前言
本篇主要分享,如何利用 Let's Encrypt 的 cert bot 來自動簽署以及更新 SSL 憑證
參考網頁
環境
設定檔
這邊使用最簡單的設定, 反向代理 server 內的 9527 port, 若無反向代理需求,可以單純指向專案的 Document root 即可
sudo vim /etc/nginx/sites-available/yourSiteName
server {
listen 80;
server_name yourDomainName;
access_log /var/log/nginx/test_access_log;
location / {
proxy_pass http://127.0.0.1:9527;
}
}測試
syntaxsudo nginx -t
啟用設定
sudo ln -s /etc/nginx/sites-available/yourSiteName /etc/nginx/sites-enabled/yourSiteName設完之後,重啟
nginxsudo service nginx restart
測試設定
設定好之後,如果我們curl http://yourIPOrDomain/endpoint, 應該要可以存取服務
新增 cerbot PPA (Personal Package Archives)
sudo apt-get update && sudo apt-get install software-properties-common && sudo add-apt-repository universe && sudo add-apt-repository ppa:certbot/certbot |
安裝 Let’s Encrypt
sudo apt-get install certbot python-certbot-nginx |
運行 cerbot
全自動模式
如果你希望 cerbot 可以幫我們全自動完成設定,輸入
sudo certbot --nginx |
半自動模式
如果你希望 cerbot 只幫我們拿到憑證,其他我們自己來的話,輸入
sudo certbot certonly --nginx |
測試自動更新
到這裡,應該已經可以自動更新憑證了,輸入以下指令測試
sudo certbot renew --dry-run |
cerbot 安裝在以下路徑之一:
/etc/crontab//etc/cron.*/*systemctl list-timers
留言