免費(fèi)SSL證書Let's Encrypt(certbot)安裝使用教程
Let's Encrypt是很火的一個(gè)免費(fèi)SSL證書發(fā)行項(xiàng)目,自動化發(fā)行證書,證書有90天的有效期。適合個(gè)人使用或者臨時(shí)使用,不用再忍受自簽發(fā)證書不受瀏覽器信賴的提示。去年VPS偵探曾經(jīng)說過Let's Encrypt的使用教程,但是Let's Encrypt已經(jīng)發(fā)布了新的工具certbot,雖然是新的工具,但是生成證書的使用方法和參數(shù)是基本一致的,證書續(xù)期更簡單了。但是目前看certbot在一些老版本的Linux發(fā)行版上的兼容性還是有問題的,特別是在CentOS 5上因?yàn)閜ython版本過低是無法用的,CentOS 6上需要先安裝epel才行,當(dāng)然也有很多第三方的工具你也可以自己去嘗試一下。
如果使用lnmp1.4,1.5的話都自帶了生成SSL的工具,直接執(zhí)行 lnmp ssl add 添加或者 lnmp vhost add 添加域名時(shí)"add ssl certificate"啟用并選擇letsencrypt。
安裝方法:
如果是CentOS 6、7,先執(zhí)行: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只是用來安裝依賴包的,也可以跳過直接到下面的生成證書的步驟,國內(nèi)VPS或服務(wù)器上使用的話建議先修改為國內(nèi)的pip源。
單域名生成證書:
./certbot-auto certonly --email youemail@vpser.net --agree-tos --no-eff-email --webroot -w /home/wwwroot/www.0794baidu.com -d www.0794baidu.com
多域名單目錄生成單證書:(即一個(gè)網(wǎng)站多個(gè)域名使用同一個(gè)證書)
./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
多域名多目錄生成一個(gè)證書:(即一次生成多個(gè)域名的一個(gè)證書)
./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。
證書續(xù)期
cerrbot的續(xù)期比原來的更加簡單,因?yàn)樽C書只有90天,所以建議使用crontab進(jìn)行自動續(xù)期:
crontab 里加上如下規(guī)則:0 3 */5 * * /root/certbot-auto renew --disable-hook-validation --renew-hook?"/etc/init.d/nginx reload"?這樣每5天就會執(zhí)行一次所有域名的續(xù)期操作。當(dāng)然時(shí)間也可以自行進(jìn)行調(diào)整,建議別太頻繁,因?yàn)樗麄兌加姓埱蟠螖?shù)的限制,如果需要強(qiáng)制更新可以在前面命令上加上 --force-renew 參數(shù)。
注意事項(xiàng):
1、因?yàn)槟J(rèn)LNMP的虛擬主機(jī)里是禁止 . 開頭的隱藏文件及目錄的,所以訪問http://abc.com/.well-known/acme-challenge/**** 這個(gè)鏈接的話返回403錯(cuò)誤,所以必須要將對應(yīng)虛擬主機(jī)配置文件里的
location ~ /\.
{
deny all;
}
這段配置刪掉或注釋掉或在這段配置前面加上
location ~ /.well-known {
allow all;
}
以上配置代碼,然后重啟nginx。
2、如果要啟用http2的話,建議編輯lnmp.conf,將里面的Nginx_Modules_Options的單引號里加上 --with-openssl=/root/openssl-1.0.2h
并執(zhí)行: 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、國內(nèi)有些用戶反映會卡在Installing Python packages...這個(gè)地方不動,因?yàn)閜ip的默認(rèn)源是國外的,國內(nèi)可能會有點(diǎn)慢,可以執(zhí)行下面命令來修改pip源為國內(nèi)的:
mkdir ~/.pip
cat > ~/.pip/pip.conf <<EOF
[global]
index-url = https://pypi.doubanio.com/simple/
[install]
trusted-host=pypi.doubanio.com
EOF
執(zhí)行完,再重新運(yùn)行certbot的命令應(yīng)該正常安裝python的包了。
有問題可以在本帖或VPS偵探論壇提問。
VPS偵探論壇邀請碼:https://bbs.vpser.net/reg.php?invitecode=41f1ca437cCC9FXe?有效期至:2016-7-8 13:07
>>轉(zhuǎn)載請注明出處:VPS偵探 本文鏈接地址:http://www.0794baidu.com/build/letsencrypt-certbot.html











@seven, 可能certbot 0.20.0 這個(gè)版本剛發(fā)布,國內(nèi)源上還沒同步過來