免費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











按照python包的時候出現以下問題. 源我已經切換過了
No matching distribution found for certbot==0.20.0 (from -r /tmp/tmp.nW2I99XHmh/letsencrypt-auto-requirements.txt (line 203))
=====================================================
Certbot has problem setting up the virtual environment.
We were not be able to guess the right solution from your pip
output.
Consult https://certbot.eff.org/docs/install.html#problems-with-python-virtual-environment
for possible solutions.
You may also find some support resources at https://certbot.eff.org/support/ .
@哈哈哈, 填你自己的郵箱就行
我使用的是Ubuntu,在輸入sudo certbot --nginx 命令之后,他要求我輸入一個郵箱,關于這個郵箱能給一個較好的介紹嗎?
博主能把第三個命令解釋一下嗎,看不懂,多域名多目錄生成一個證書:哪個是域名目錄,哪個是域名,哪個是共用證書目錄??
@klmahua, 第三個生成命令就是
360網站加速開啟https需要上傳crt文件及key文件,請問博主,,這兩個文件在哪個位置,,,我找到的fullchain.pem文件怎么下載不下來?求博主幫忙!!!
博主,多個網站不同二級域名能使用同一個證書嗎?比如主站門戶域名是:www.xxx.com,論壇域名是:bbs.xxx.com,論壇和門戶能同時使用門戶的證書嗎,如過可以,求怎么配置?
@佚名, 可能證書有問題,也可能網頁中含有非https內容
已經上了https,但是瀏覽器會提示無法驗證服務器身份,需要點擊信任,怎么辦啊?
@klmahua, yum install nss 后再試試,也可以直接wget后rpm -i 文件名進行安裝
centos6 執行 yum install epel-release 安裝失敗
錯誤提示:
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Error: Cannot retrieve metalink for repository: epel. Please verify its path and try again
執行rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm 也安裝失敗
錯誤提示:
Retrieving https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm
curl: (35) SSL connect error
error: skipping https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm - transfer failed
求博主解決!!!
@klmahua, 安裝上epel 參考文中方法或 http://www.0794baidu.com/manage/centos-rhel-linux-third-party-source-epel.html
執行./certbot-auto -n
提示
Bootstrapping dependencies for RedHat-based OSes...
yum is /usr/bin/yum
To use Certbot, packages from the EPEL repository need to be installed.
Please enable this repository and try running Certbot again.
怎么解決???
@qsau, 這個和配置沒有關系,你自己手動pip install virtualenv 看一下是不是從修改后的源上下載安裝
我換了一個2核4G的做了相同操作,也是卡在install python package 上了,應該不是配置問題了。大神,有沒有解決方案?
安裝certbot的服務器最低配置是什么?
我的1核1G的阿里云服務器是否能安裝?
我系統是centos7.0安裝certbot時在install python package時卡住了,我把進程kill掉,修改了pip源,但是依舊卡在這個地方,是不是我的服務器配置過低導致的還是其他什么原因?