Let's Encrypt 免费SSL配置
2019獨(dú)角獸企業(yè)重金招聘Python工程師標(biāo)準(zhǔn)>>>
官方網(wǎng)址?https://letsencrypt.org/
UPDATE:
[2018/10/26]如果創(chuàng)建證書(shū)時(shí)出現(xiàn)?Client with the currently selected authenticator does not support any combination of challenges that will satisfy the CA.,表示要更新你的certbot工具了,如果是certos,簡(jiǎn)單的執(zhí)行yum update certbot就行了。參考這里。
高能提醒:
[1] Let's Encrypt實(shí)測(cè)還是有兼容性問(wèn)題(兼容性在這里測(cè)試,java 6u45和java 7u80都不兼容),特別是java程序里,會(huì)被不信任(如錯(cuò)誤提示:您需要設(shè)置證書(shū)才能訪問(wèn)此網(wǎng)址,PKIX path building failed: unable to find valid certification path to requested target)。因?yàn)閖ava會(huì)自己維護(hù)一份keystore,目錄在?$JAVA_HOME/lib/security/cacerts(詳情解釋在這),里面放了大部分公開(kāi)的可信CA ROOT證書(shū)(關(guān)于根證書(shū)更新的方法可以參考微信的這個(gè)幫助說(shuō)明,當(dāng)然,每家CA的root證書(shū)是不同的,不要照搬照抄,去CA的官方找ROOT證書(shū)再更新),但并不包含Let's Encrypt,特別是一些老的運(yùn)行環(huán)境,解決辦法可以手工添加(點(diǎn)此處下載Let's Encrypt CA Root,關(guān)于Let's Encrypt CA的詳細(xì)介紹)或用這個(gè)程序自動(dòng)添加,下載這個(gè)代碼 http://blogs.sun.com/andreas/resource/InstallCert.java,編譯后運(yùn)行,更新keystore #java InstallCert www.example.com
[2] 關(guān)于Let's Encrypt 與 Java 運(yùn)行環(huán)境的問(wèn)題參考這里。Java 7 >= 7u111 and Java 8 >= 8u101 已經(jīng)支持,但依賴于JVM環(huán)境,如JDK/JRE 到8u66還沒(méi)有完全自動(dòng)支持。
[3]如何查詢java運(yùn)行環(huán)境已經(jīng)支持的CA ROOT證書(shū),代碼在這。默認(rèn)密碼是changeit
轉(zhuǎn)入正題,開(kāi)始安裝Let's Encrypt SSL
環(huán)境:CentOS Linux release 7.4.1708 (Core);欲添加ssl的域名必須是可以直接訪問(wèn)的,因?yàn)樾枰clet's encrypt服務(wù)器進(jìn)行正反雙向的握手通訊認(rèn)證,如果是修改hosts方式定義的域名無(wú)法生成ssl證書(shū);
1.安裝支持軟件
yum install certbot-nginx
升級(jí)pip
pip install --upgrade pip
如果pyOpenSSL版本小于0.14(比如阿里云的yum倉(cāng)庫(kù)),則要先刪除再獨(dú)立安裝最新版本(如果yum庫(kù)沒(méi)有最新版本的話,有的話直接從yum安裝)
yum erase pyOpenSSL (此命令會(huì)同步刪除certbot-nginx,不可使用)
rpm -e --nodeps pyOpenSSL
pip install --upgrade pyOpenSSL
2.配置單域名方式
如果域名和IP在同一臺(tái)機(jī)器上,則執(zhí)行自動(dòng)配置命令:
certbot --nginx
如果想安全一點(diǎn)不讓程序自動(dòng)修改Nginx.conf,則執(zhí)行手工配置命令:
certbot --nginx certonly
根據(jù)命令提示一步一步,每次只能選擇一個(gè)域名,雖然提示說(shuō)可以逗號(hào)分多個(gè)選擇,但實(shí)際測(cè)試不支持。另外注意結(jié)束的提示,有pem證書(shū)和密鑰文件保存的位置要記錄下來(lái),以后有用到,如
/etc/letsencrypt/live/tf.example.com/fullchain.pem
/etc/letsencrypt/live/tf.example.com/privkey.pem
配置完后一定要測(cè)試?yán)m(xù)訂命令有沒(méi)有報(bào)錯(cuò):certbot renew,如果有報(bào)錯(cuò),可以刪除一些配置/etc/letsencrypt/renewal/,重試。
2.配置通配符方式
安裝DNS插件,目前只有部分DNS服務(wù)商提供了這個(gè)服務(wù)(國(guó)內(nèi)大部分DNS商家都沒(méi)有)
https://certbot.eff.org/docs/using.html#dns-plugins
certbot-dns-cloudflare
certbot-dns-cloudxns
certbot-dns-digitalocean
certbot-dns-dnsimple
certbot-dns-dnsmadeeasy
certbot-dns-google
certbot-dns-luadns
certbot-dns-nsone
certbot-dns-rfc2136
certbot-dns-route53
DNS插件安裝成功后提示命令
certbot -a dns-plugin -i nginx -d "*.example.com" -d example.com --server https://acme-v02.api.letsencrypt.org/directory
3.因Let's Encrpty三個(gè)月過(guò)期,可以自動(dòng)續(xù)訂
certbot renew --dry-run
安裝腳本到cron里
certbot renew
例如:
0 0,12 * * * python -c 'import random; import time; time.sleep(random.random() * 3600)' && certbot renew?
4.配置備份
帳號(hào)等配置放在這個(gè)目錄下,要做好這個(gè)目錄下文件的備份。
/etc/letsencrypt
附錄
[1]安裝時(shí)報(bào)錯(cuò):ImportError: No module named 'requests.packages.urllib3',是因數(shù)Centos7的BUG,請(qǐng)用此命令強(qiáng)制升級(jí)?pip install requests urllib3 pyOpenSSL --force --upgrade,如果有提示某些包被其他管理器安裝的,這里是yum,則先刪除后再執(zhí)行,如夢(mèng)
rpm -e --nodeps python-enum34
rpm -e --nodeps python-ipaddress
[2] 從泛域名換成單個(gè)域名,發(fā)現(xiàn)某些java程序調(diào)用ssl鏈接會(huì)報(bào)錯(cuò),如PKIX path building failed: unable to find valid certification path to requested target,具體原因跟java運(yùn)行環(huán)境對(duì)ssl密鑰的管理有關(guān),因?yàn)長(zhǎng)et's Encrypt 還不是大眾都接受的證書(shū)供應(yīng)商,所以對(duì)部分客戶端的支持不是那么友好,解決方案參考這里?或 這里自動(dòng)更新java的證書(shū)。另外遇到的一個(gè)問(wèn)題時(shí),有的java環(huán)境會(huì)緩存另外的域名的情況,如果提示hostname不一致,則可以刪除那個(gè)域名試下(如果不重要的域名),致于java環(huán)境如果會(huì)緩存到未提供過(guò)的域名,原因還未知。
[3]centos 7下面如何直接certbot renew時(shí)報(bào)如下錯(cuò)誤,
ImportError: 'pyOpenSSL' module missing required functionality. Try upgrading to v0.14 or newer.
則執(zhí)行
mv /usr/lib64/python2.7/site-packages/OpenSSL /usr/lib64/python2.7/site-packages/pyOpenSSL
具體參考討論,這是一種不太安全的做法,不知會(huì)不會(huì)其他負(fù)作用??梢試L試下面的方法:
rpm --query centos-release ?# centos-release-7-3.1611.el7.centos.x86_64
wget ftp://ftp.muug.ca/mirror/centos/7/cloud/x86_64/openstack-newton/common/pyOpenSSL-0.15.1-1.el7.noarch.rpm
sudo rpm -Uvh pyOpenSSL-0.15.1-1.el7.noarch.rpm
sudo yum install certbot
certbot renew ?# OK
參考資料
[1]?https://certbot.eff.org/lets-encrypt/centosrhel7-nginx
[2]Issues:?https://github.com/certbot/certbot/issues/5104
轉(zhuǎn)載于:https://my.oschina.net/swingcoder/blog/1821221
總結(jié)
以上是生活随笔為你收集整理的Let's Encrypt 免费SSL配置的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: python序列化模块json和pick
- 下一篇: []ARC098