Let's Encrypt是很火的一個免費SSL證書發行項目,自動化發行證書,證書有90天的有效期。Let's Encrypt已經發布了工具certbot,用此工具生成證書、證書續期很是簡單。nginx
如下是用certbot生成通配符域名證書的使用方法(Centos7爲例):web
執行:api
certbot certonly -d *.domain.com --manual --preferred-challenges dns --server https://acme-v02.api.letsencrypt.org/directory
Are you OK with your IP being logged?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: Y
Please deploy a DNS TXT record under the name _acme-challenge.domain.com with the following value: ************* Before continuing, verify the record is deployed.
根據提示,這裏須要手動到域名解析的地方添加域名的TXT解析,完成後過幾分鐘等待生效,並使用nslookup命令檢查一下是否生效:服務器
nslookup -q=TXT _acme-challenge.domain.com
若TXT解析已生效,在certbot命令行界面敲入回車,進行校驗,證書生成成功後提示以下以下:網絡
IMPORTANT NOTES: - Congratulations! Your certificate and chain have been saved at: /etc/letsencrypt/live/domain.com/fullchain.pem Your key file has been saved at: /etc/letsencrypt/live/domain.com/privkey.pem Your cert will expire on 2019-11-19. To obtain a new or tweaked version of this certificate in the future, simply run certbot again. To non-interactively renew *all* of your certificates, run "certbot 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
而後回到阿里雲SLB中,找到添加證書的地方,選擇已有證書方式進行添加。dom
cat命令查看公鑰、私鑰,並複製到阿里雲添加證書的界面中。ide
查看公鑰:工具
cat /etc/letsencrypt/live/domain.com/fullchain.pem
阿里雲要求私鑰是-----BEGIN RSA PRIVATE KEY-----開頭,因此須要先處理如下私鑰文件,轉換成RSA私鑰,執行如下命令:網站
openssl rsa -in /etc/letsencrypt/live/domain.com/privkey.pem -out /etc/letsencrypt/live/domain.com/privkey.rsa.pem
查看私鑰:ui
cat /etc/letsencrypt/live/domain.com/privkey.rsa.pem
之後若須要續SSL證書,只需在該服務器上執行如下命令,並按提示繼續:
certbot renew
如下是certbot-auto的使用方法,內容來源於網絡,供參考借鑑:
安裝方法:
若是是CentOS 六、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.vpser.net -d www.vpser.net
多域名單目錄生成單證書:(即一個網站多個域名使用同一個證書)
./certbot-auto certonly --email youemail@vpser.net --agree-tos --no-eff-email --webroot -w /home/wwwroot/www.vpser.net -d www.vpser.net -d bbs.vpser.net
多域名多目錄生成一個證書:(即一次生成多個域名的一個證書)
./certbot-auto certonly --email youemail@vpser.net --agree-tos --no-eff-email --webroot -w /home/wwwroot/www.vpser.net -d www.vpser.net -d bbs.vpser.net -w /home/wwwroot/lnmp.org -d www.lnmp.org -d lnmp.org
證書續期
cerrbot的續期比原來的更加簡單,由於證書只有90天,因此建議使用crontab進行自動續期:
crontab 里加上以下規則:0 3 */5 * * /root/certbot-auto renew --disable-hook-validation --renew-hook "/etc/init.d/nginx reload" 這樣每5天就會執行一次全部域名的續期操做。固然時間也能夠自行進行調整,建議別太頻繁,由於他們都有請求次數的限制,若是須要強制更新能夠在前面命令上加上 --force-renew 參數。