在CentOS6,CentOS7安装 Let'sEncrypt 免费SSL安全证书
Posted 岁月无心
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了在CentOS6,CentOS7安装 Let'sEncrypt 免费SSL安全证书相关的知识,希望对你有一定的参考价值。
相对来说,个人网站建立SSL是昂贵的,而且往往过程繁琐。一个标准的2048位证书费用至少150美元/年,网站除了要支付一笔昂贵的费用、重新配置Web服务器,并需要解决大量的配置错误。这让广大中小网站望而生畏。
然而,Let‘s Encrypt免费证书的开放,极大推进了国内 HTTPS 的进程。Let‘s Encrypt 真正的意义在于,它推动了 HTTPS 在小型网站和个人网站中的应用,加速全面 HTTPS 时代的到来。Let‘s Encrypt 的最大贡献是它的 ACME 协议,第一份全自动服务器身份验证协议,以及配套的基础设施和客户端。这是为了解决一直以来 HTTPS TLS X.509 PKI 信任模型,即证书权威(Certificate Authority, CA)模型缺陷的一个起步。
Let‘sEncrypt的工作原理
看图:
ACME 解决了私钥持有者验证自己身份这一过程的自动化问题。
在CentOS6,CentOS7上安装Let‘s Encrypt
非营利组织电子前沿基金会的CertBot是一个很好的工具,我们使用它来安装Let‘s Encrypt
一、升级系统
- # yum -y update
二、安装EPEL库,为CertBot提供最新的Python包。
- # yum -y install epel-release
三、下载CertBot
1、CentOS7:
- # yum -y install python-certbot-apache
2、CentOS6:
- # wget https://dl.eff.org/certbot-auto
- # chmod 755 certbot-auto
四、Apache下配置Let‘s Encrypt
执行下条命令
- # ./certbot-auto --apache
根据提示操作
- /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 ->
五、打开防火墙iptables的443端口
- -A INPUT -m state --state NEW -m tcp -p tcp --dport 443 -j ACCEPT
- #service iptables restart
六、编辑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
七、这个时候网站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]
八、大功告成
注意:Let‘sEncrypt的证书有效期为90天,因此,建议使用cron作业在证书到期前一周将证书renew
以上是关于在CentOS6,CentOS7安装 Let'sEncrypt 免费SSL安全证书的主要内容,如果未能解决你的问题,请参考以下文章