相對來講,我的網站創建SSL是昂貴的,並且每每過程繁瑣。一個標準的2048位證書費用至少150美圓/年,網站除了要支付一筆昂貴的費用、從新配置Web服務器,並須要解決大量的配置錯誤。這讓廣大中小網站望而生畏。html
然而,Let's Encrypt免費證書的開放,極大推動了國內 HTTPS 的進程。Let's Encrypt 真正的意義在於,它推進了 HTTPS 在小型網站和我的網站中的應用,加速全面 HTTPS 時代的到來。Let's Encrypt 的最大貢獻是它的 ACME 協議,第一份全自動服務器身份驗證協議,以及配套的基礎設施和客戶端。這是爲了解決一直以來 HTTPS TLS X.509 PKI 信任模型,即證書權威(Certificate Authority, CA)模型缺陷的一個起步。python
Let'sEncrypt的工做原理
看圖:git
ACME 解決了私鑰持有者驗證本身身份這一過程的自動化問題。web
在CentOS6,CentOS7上安裝Let's Encrypt
非營利組織電子前沿基金會的CertBot是一個很好的工具,咱們使用它來安裝Let's Encryptapache
1、升級系統
- # yum -y update
2、安裝EPEL庫,爲CertBot提供最新的Python包。
- # yum -y install epel-release
3、下載CertBot
一、CentOS7:api
- # yum -y install python-certbot-apache
二、CentOS6:服務器
- # wget https://dl.eff.org/certbot-auto
- # chmod 755 certbot-auto
4、Apache下配置Let's Encrypt
執行下條命令app
- # ./certbot-auto --apache
根據提示操做tcp
- /root/.local/share/letsencrypt/lib/python2.6/site-packages/cryptography/__init__.py:26: DeprecationWarning: Python 2.6 is no longer supported by the Python core team, please upgrade your Python. A future version of cryptography will drop support for Python 2.6
- DeprecationWarning
- Saving debug log to /var/log/letsencrypt/letsencrypt.log
- Enter email address (used for urgent renewal and security notices) (Enter 'c' to
- cancel):輸入管理員郵箱
-
- -------------------------------------------------------------------------------
- Please read the Terms of Service at
- https://letsencrypt.org/documents/LE-SA-v1.1.1-August-1-2016.pdf. You must agree
- in order to register with the ACME server at
- https://acme-v01.api.letsencrypt.org/directory
- -------------------------------------------------------------------------------
- (A)gree/(C)ancel: A
-
- -------------------------------------------------------------------------------
- Would you be willing to share your email address with the Electronic Frontier
- Foundation, a founding partner of the Let's Encrypt project and the non-profit
- organization that develops Certbot? We'd like to send you email about EFF and
- our work to encrypt the web, protect its users and defend digital rights.
- -------------------------------------------------------------------------------
- (Y)es/(N)o: Y
-
- Which names would you like to activate HTTPS for?
- -------------------------------------------------------------------------------
- 1: www.xi-chuang.com
- -------------------------------------------------------------------------------
- Select the appropriate numbers separated by commas and/or spaces, or leave input
- blank to select all options shown (Enter 'c' to cancel):1
- Obtaining a new certificate
成功後,在/etc/letsencrypt/live/www.xi-chuang.com/下生成4個證書:工具
- cert.pem ->
- chain.pem ->
- fullchain.pem ->
- privkey.pem ->
5、打開防火牆iptables的443端口
- -A INPUT -m state --state NEW -m tcp -p tcp --dport 443 -j ACCEPT
- #service iptables restart
6、編輯ssl.conf
vi /etc/httpd/conf.d/ssl.conf
- # General setup for the virtual host, inherited from global configuration
- DocumentRoot "/var/www/html/xi-chuang.com"
- ServerName www.xi-chuang.com:443
- .
- .
- .
- SSLCertificateFile /etc/letsencrypt/live/www.xi-chuang.com/fullchain.pem
- .
- .
- .
- SSLCertificateKeyFile /etc/letsencrypt/live/www.xi-chuang.com/privkey.pem
- .
- .
- .
service httpd restart
7、這個時候網站HTTPS已經可以訪問了,試一下
最後,經過.htaccess進行301轉向
- RewriteEngine On
- RewriteCond %{SERVER_PORT} 80
- RewriteRule ^(.*)$ https://www.xi-chuang.com/$1 [R=301,L]
- RewriteCond %{HTTP_HOST} !^www.xi-chuang.com$ [NC]
- RewriteRule ^(.*)$ https://www.xi-chuang.com/$1 [L,R=301]
8、大功告成
注意:Let'sEncrypt的證書有效期爲90天,所以,建議使用cron做業在證書到期前一週將證書renew