使用Cerbot自動化申請lets-encrypt證書


這里介紹的是ubuntu + Nginx環境,完全自動化部署,包括nginx配置也自動幫你配置好,https就是這么簡單

安裝

第一次使用Cerbot需要先安裝

下面的命令都需要root權限,如果不是root用戶,需要加上sudo

1
2
3
4
5
apt update
apt install software-properties-common
add-apt-repository ppa:certbot/certbot
apt update
apt install python-certbot-nginx

注意:如果出現找不到軟件包可試運行: apt-get install certbot ;查看版本:uname -a 或者 cat /proc/version

如果系統版本過老請參考:
http://pan.com/index.php?share/file&user=207&sid=A8Qrua4p

准備工作

域名解析

因為需要驗證服務器和域名,所以要把需要申請證書的域名解析到當前操作服務器,不能使用CDN,如果正在用CDN需要先暫停並把域名直接解析到服務器上。

nginx綁定

確保你的域名現在是可以訪問的,已經在監聽80端口中,這樣才能實現自動添加443端口配置

使用

就一個命令: certbot --nginx

會展示目前nginx正在啟用的域名

1.certbot --nginx

Which names would you like to activate HTTPS for?
-------------------------------------------------------------------------------
1: lmlq.com
2: www.lmlq.com

這時候可以輸入數字 選擇要添加https的站

如果不輸入則將所有列出的域名添加https

輸入回車后開始驗證域名解析

1
2
3
4
5
6
7
8
Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access.
-------------------------------------------------------------------------------
1: No redirect - Make no further changes to the webserver configuration.
2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for
new sites, or if you're confident your site works on HTTPS. You can undo this
change by editing your web server's configuration.
-------------------------------------------------------------------------------
Select the appropriate number [1-2] then [enter] (press 'c' to cancel):

選擇2 http重定向到https

選擇1 http和https並存

從SEO方面考慮 推薦選2

輸入回車后開始配置

完成

 

續期

手動續期:

certbot renew --dry-run

設置定時任務:

crontab -e

如果第一次使用 需要輸入1-4選擇編輯器

添加一行

1.  15 3 9 * * /usr/bin/certbot renew --dry-run > /dev/null
2. #15分3時9日

 

每月的9號執行一次,可以自行修改

 

查看定時任務:

crontab -l
關於其他的環境的自動化部署可以參考 certbot官網


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM