免費SSL證書Let's Encrypt(certbot)安裝使用教程
Let's Encrypt是很火的一個免費SSL證書發行項目,自動化發行證書,證書有90天的有效期。適合個人使用或者臨時使用,不用再忍受自簽發證書不受瀏覽器信賴的提示。去年VPS偵探曾經說過Let's Encrypt的使用教程,但是Let's Encrypt已經發布了新的工具certbot,雖然是新的工具,但是生成證書的使用方法和參數是基本一致的,證書續期更簡單了。但是目前看certbot在一些老版本的Linux發行版上的兼容性還是有問題的,特別是在CentOS 5上因為python版本過低是無法用的,CentOS 6上需要先安裝epel才行,當然也有很多第三方的工具你也可以自己去嘗試一下。
如果使用lnmp1.4,1.5的話都自帶了生成SSL的工具,直接執行 lnmp ssl add 添加或者 lnmp vhost add 添加域名時"add ssl certificate"啟用并選擇letsencrypt。
安裝方法:
如果是CentOS 6、7,先執行:yum install epel-release
cd /root/ wget https://dl.eff.org/certbot-auto --no-check-certificate chmod +x ./certbot-auto ./certbot-auto -n
./certbot-auto -n只是用來安裝依賴包的,也可以跳過直接到下面的生成證書的步驟,國內VPS或服務器上使用的話建議先修改為國內的pip源。
單域名生成證書:
./certbot-auto certonly --email youemail@vpser.net --agree-tos --no-eff-email --webroot -w /home/wwwroot/www.0794baidu.com -d www.0794baidu.com
多域名單目錄生成單證書:(即一個網站多個域名使用同一個證書)
./certbot-auto certonly --email youemail@vpser.net --agree-tos --no-eff-email --webroot -w /home/wwwroot/www.0794baidu.com -d www.0794baidu.com -d bbs.vpser.net
多域名多目錄生成一個證書:(即一次生成多個域名的一個證書)
./certbot-auto certonly --email youemail@vpser.net --agree-tos --no-eff-email --webroot -w /home/wwwroot/www.0794baidu.com -d www.0794baidu.com -d bbs.vpser.net -w /home/wwwroot/lnmp.org -d www.lnmp.org -d lnmp.org
提示
IMPORTANT NOTES:
- Congratulations! Your certificate and chain have been saved at
/etc/letsencrypt/live/www.0794baidu.com/fullchain.pem. Your cert will
expire on 2016-10-01. To obtain a new or tweaked version of this
certificate in the future, simply run certbot-auto again. To
non-interactively renew *all* of your certificates, run
"certbot-auto renew"
- If you like Certbot, please consider supporting our work by:Donating to ISRG / Let's Encrypt: https://letsencrypt.org/donate
Donating to EFF: https://eff.org/donate-le
就是生成成功。
生成的證書會存在:/etc/letsencrypt/live/www.0794baidu.com/ 目錄下
具體Nginx和Apache的配置可以參考:http://www.0794baidu.com/build/letsencrypt-free-ssl.html 里的配置文件。
修改完配置文件切記重啟或reload nginx。
證書續期
cerrbot的續期比原來的更加簡單,因為證書只有90天,所以建議使用crontab進行自動續期:
crontab 里加上如下規則:0 3 */5 * * /root/certbot-auto renew --disable-hook-validation --renew-hook?"/etc/init.d/nginx reload"?這樣每5天就會執行一次所有域名的續期操作。當然時間也可以自行進行調整,建議別太頻繁,因為他們都有請求次數的限制,如果需要強制更新可以在前面命令上加上 --force-renew 參數。
注意事項:
1、因為默認LNMP的虛擬主機里是禁止 . 開頭的隱藏文件及目錄的,所以訪問http://abc.com/.well-known/acme-challenge/**** 這個鏈接的話返回403錯誤,所以必須要將對應虛擬主機配置文件里的
location ~ /\.
{
deny all;
}
這段配置刪掉或注釋掉或在這段配置前面加上
location ~ /.well-known {
allow all;
}
以上配置代碼,然后重啟nginx。
2、如果要啟用http2的話,建議編輯lnmp.conf,將里面的Nginx_Modules_Options的單引號里加上 --with-openssl=/root/openssl-1.0.2h
并執行: cd /root && wget -c?https://www.openssl.org/source/openssl-1.0.2h.tar.gz && tar zxf?openssl-1.0.2h.tar.gz ,然后使用升級腳本 ./upgrade.sh nginx 升級nginx至1.9.5或更高版本。
3、國內有些用戶反映會卡在Installing Python packages...這個地方不動,因為pip的默認源是國外的,國內可能會有點慢,可以執行下面命令來修改pip源為國內的:
mkdir ~/.pip
cat > ~/.pip/pip.conf <<EOF
[global]
index-url = https://pypi.doubanio.com/simple/
[install]
trusted-host=pypi.doubanio.com
EOF
執行完,再重新運行certbot的命令應該正常安裝python的包了。
有問題可以在本帖或VPS偵探論壇提問。
VPS偵探論壇邀請碼:https://bbs.vpser.net/reg.php?invitecode=41f1ca437cCC9FXe?有效期至:2016-7-8 13:07
>>轉載請注明出處:VPS偵探 本文鏈接地址:http://www.0794baidu.com/build/letsencrypt-certbot.html











@seven, 可能certbot 0.20.0 這個版本剛發布,國內源上還沒同步過來