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