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











@沒有live文件夾, IP解析的對嗎?填寫的網站目錄正確嗎,看它去請求驗證返回的文件是不對的
請問下在執行命令:
單域名生成證書:
./certbot-auto certonly xxxxxx
之后在/etc/letsencrypt/ 目錄下并沒有生成live等文件夾,目錄下就只有 accounts renewal 兩個目錄
提示信息為:
IMPORTANT NOTES:
- The following errors were reported by the server:
Domain: http://www.admol.net
Type: unauthorized
Detail: Invalid response from
http://www.xxxxxxxxx.xxx/.well-known/acme-challenge/xxxxx
"
<meta http-equiv="X-UA-Compatible" content="IE=edge""
To fix these errors, please make sure that your domain name was
entered correctly and the DNS A record(s) for that domain
contain(s) the right IP address.
請問下這是為什么呢
@偏執者, 沒遇到過這個估計可能是被系統kill了,centos上的話安裝的依賴包基本上是python python-libs python-devel python-tools python-pip python-virtualenv dialog libffi-devel augeas-libs這些,yum命令裝一下就行,還是可在安裝包下載安裝那邊的話估計就是你設置的系統源慢了,再就是還會pip安裝一下軟件包,國內的話也可以嘗試改成一些國內的pip源
補充一下錯誤代碼
Creating virtual environment...
Installing Python packages...
/root/certbot-auto: line 1147: 14764 Killed "$0" --le-auto-phase2 "$@"
Connection closed.
軍哥,使用您的教程成功安裝部署SSL證書。
但是在使用您的續期指令 /root/certbot-auto renew 之后,停留在這一步 Installing Python packages... 幾個小時都沒有任何反應,重復嘗試多次均為同樣情況,停留到這一步沒有任何反應。請問這個問題如何解決?
@xiangyudashu, python2.6下支持有問題,這上面沒有具體最后的錯誤信息不好說
軍哥 執行完 ./certbot-auto -n
之后,提示
WARNING: unable to check for updates.
Creating virtual environment...
Installing Python packages...
Traceback (most recent call last):
File "/tmp/tmp.7G60uNOf6f/pipstrap.py", line 146, in
exit(main())
File "/tmp/tmp.7G60uNOf6f/pipstrap.py", line 130, in main
for url, digest in PACKAGES]
File "/tmp/tmp.7G60uNOf6f/pipstrap.py", line 112, in hashed_download
response = opener().open(url)
File "/usr/lib/python2.6/urllib2.py", line 391, in open
response = self._open(req, data)
File "/usr/lib/python2.6/urllib2.py", line 409, in _open
'_open', req)
File "/usr/lib/python2.6/urllib2.py", line 369, in _call_chain
result = func(*args)
File "/usr/lib/python2.6/urllib2.py", line 1198, in https_open
return self.do_open(httplib.HTTPSConnection, req)
File "/usr/lib/python2.6/urllib2.py", line 1165, in do_open
raise URLError(err)
urllib2.URLError:
這個是怎么個情況?求軍哥百忙之中抽空給個解答啊
@LisonFan, 這個只是讓他來安裝依賴包,有這個提示肯定依賴包已經安裝好了
執行完 ./certbot-auto -n
最后提示如下:
Missing command line flags. For non-interactive execution, you will need to specify a plugin on the command line. Run with '--help plugins' to see a list of options, and see https://eff.org/letsencrypt-plugins for more detail on what the plugins do and how to use them.
是什么意思呢?
@hjoker, fullchain.pem 中就包含中間證書
按照教程安裝了,現在chrome提示不受信任的證書。。。網上查了說是缺少中間證書,求破
@Chilsion, 沒按要求裝epel吧
CentOS 6.8 nginx環境。執行
cd /root/
wget https://dl.eff.org/certbot-auto --no-check-certificate
chmod +x ./certbot-auto
./certbot-auto -n
后,出現以下錯誤,請問怎么解決?
Complete!
Creating virtual environment...
Traceback (most recent call last):
File "/usr/bin/virtualenv", line 2, in
import virtualenv
ImportError: No module named virtualenv
@邀請碼, 文章末尾自己找
http://bbs.vpser.net/邀請碼 是多少啊
驗證碼