Week 8, continued
目录:
让我们加密是由Internet安全研究组(ISRG)开发的免费,自动化和开放的证书颁发机构。 从加密之日起,Let's Encrypt颁发的证书有效期为90天,并受到当今所有主要浏览器的信任。
在本教程中,我们将介绍在运行Apache作为Web服务器的CentOS 7服务器上安装免费的Let's Encrypt SSL证书的必要步骤。 我们将使用certbot实用程序来获取和续订我们的加密证书。
先决条件
在继续本教程之前,请确保满足以下先决条件:
- 有一个指向您的公共服务器IP的域名。 我们将使用
example.com.Apache已安装并在您的服务器上运行。您的域具有Apache虚拟主机。端口80和443在防火墙中处于打开状态。
安装以下SSL加密的Web服务器所需的软件包:
安装Certbot
Certbot是一种工具,可简化从Let's Encrypt获取SSL证书并在服务器上自动启用HTTPS的过程。
certbot软件包可从EPEL安装。 如果您的系统上未安装EPEL存储库,则可以使用以下命令进行安装:
sudo yum install epel-release
启用EPEL存储库后,通过输入以下内容安装certbot软件包:
产生强Dh(Diffie-Hellman)组
Diffie-Hellman密钥交换(DH)是一种在不安全的通信通道上安全地交换加密密钥的方法。 生成一组新的2048位DH参数以增强安全性:
sudo openssl dhparam -out /etc/ssl/certs/dhparam.pem 2048
您最多可以更改4096位的大小,但是在这种情况下,生成时间可能会超过30分钟,具体取决于系统的熵。
获取“让我们加密SSL”证书
为了获得我们域的SSL证书,我们将使用Webroot插件,该插件的工作方式是在
${webroot-path}/.well-known/acme-challenge
目录中创建一个用于验证请求的域的临时文件。 Let's Encrypt服务器向临时文件发出HTTP请求,以验证请求的域是否解析为certbot运行的服务器。
为了更简单,我们将所有针对
.well-known/acme-challenge
HTTP请求映射到一个目录
/var/lib/letsencrypt
。
运行以下命令以创建目录并使该目录可用于Apache服务器:
sudo mkdir -p /var/lib/letsencrypt/.well-known
sudo chgrp apache /var/lib/letsencrypt
sudo chmod g+s /var/lib/letsencrypt
为避免重复代码,请创建以下两个配置片段:
Alias /.well-known/acme-challenge/ "/var/lib/letsencrypt/.well-known/acme-challenge/" AllowOverride None Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec Require method GET POST OPTIONS
Alias /.well-known/acme-challenge/ "/var/lib/letsencrypt/.well-known/acme-challenge/" AllowOverride None Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec Require method GET POST OPTIONS
SSLCipherSuite EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH SSLProtocol All -SSLv2 -SSLv3 -TLSv1 -TLSv1.1 SSLHonorCipherOrder On Header always set Strict-Transport-Security "max-age=63072000; includeSubDomains; preload" Header always set X-Frame-Options DENY Header always set X-Content-Type-Options nosniff # Requires Apache >= 2.4 SSLCompression off SSLUseStapling on SSLStaplingCache "shmcb:logs/stapling-cache(150000)" # Requires Apache >= 2.4.11 SSLSessionTickets Off
上面的代码片段使用了Cipherli.st推荐的削片程序,启用了OCSP装订,HTTP严格传输安全性(HSTS)并仅实施了一些针对安全性的HTTP标头。
重新加载Apache配置以使更改生效:
sudo systemctl reload
现在,我们可以使用webroot插件运行Certbot工具,并通过输入以下内容获取SSL证书文件:
sudo certbot certonly --agree-tos --email [email protected] --webroot -w /var/lib/letsencrypt/ -d example.com -d www.example.com
如果成功获得SSL证书,certbot将显示以下消息:
IMPORTANT NOTES: - Congratulations! Your certificate and chain have been saved at: /etc/letsencrypt/live/example.com/fullchain.pem Your key file has been saved at: /etc/letsencrypt/live/example.com/privkey.pem Your cert will expire on 2018-12-07. 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:
CentOS 7随附Apache版本2.4.6,其中不包含
SSLOpenSSLConfCmd
指令。 该指令仅在以后的Apache 2.4.8中可用,并且用于配置OpenSSL参数,例如Diffie-Hellman密钥交换(DH)。
我们将不得不使用Let's Encrypt SSL证书和生成的DH文件创建一个新的组合文件。 为此,请键入:
cat /etc/letsencrypt/live/example.com/cert.pem /etc/ssl/certs/dhparam.pem >/etc/letsencrypt/live/example.com/cert.dh.pem
现在已完成所有设置,按如下所示编辑域虚拟主机配置:
/etc/httpd/conf.d/example.com.conf
ServerName example.com ServerAlias www.example.com Redirect permanent / https://example.com/ ServerName example.com ServerAlias www.example.com Redirect permanent / https://example.com/ DocumentRoot /var/www/example.com/public_html ErrorLog /var/log/httpd/example.com-error.log CustomLog /var/log/httpd/example.com-access.log combined SSLEngine On SSLCertificateFile /etc/letsencrypt/live/example.com/cert.dh.pem SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem SSLCertificateChainFile /etc/letsencrypt/live/example.com/chain.pem # Other Apache Configuration
ServerName example.com ServerAlias www.example.com Redirect permanent / https://example.com/ ServerName example.com ServerAlias www.example.com Redirect permanent / https://example.com/ DocumentRoot /var/www/example.com/public_html ErrorLog /var/log/httpd/example.com-error.log CustomLog /var/log/httpd/example.com-access.log combined SSLEngine On SSLCertificateFile /etc/letsencrypt/live/example.com/cert.dh.pem SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem SSLCertificateChainFile /etc/letsencrypt/live/example.com/chain.pem # Other Apache Configuration
ServerName example.com ServerAlias www.example.com Redirect permanent / https://example.com/ ServerName example.com ServerAlias www.example.com Redirect permanent / https://example.com/ DocumentRoot /var/www/example.com/public_html ErrorLog /var/log/httpd/example.com-error.log CustomLog /var/log/httpd/example.com-access.log combined SSLEngine On SSLCertificateFile /etc/letsencrypt/live/example.com/cert.dh.pem SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem SSLCertificateChainFile /etc/letsencrypt/live/example.com/chain.pem # Other Apache Configuration
ServerName example.com ServerAlias www.example.com Redirect permanent / https://example.com/ ServerName example.com ServerAlias www.example.com Redirect permanent / https://example.com/ DocumentRoot /var/www/example.com/public_html ErrorLog /var/log/httpd/example.com-error.log CustomLog /var/log/httpd/example.com-access.log combined SSLEngine On SSLCertificateFile /etc/letsencrypt/live/example.com/cert.dh.pem SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem SSLCertificateChainFile /etc/letsencrypt/live/example.com/chain.pem # Other Apache Configuration
使用上述配置,我们将强制HTTPS并从www重定向到非www版本。 随意根据您的需要调整配置。
重新启动Apache服务以使更改生效:
sudo systemctl restart
您现在可以使用
https://
打开网站,您会注意到一个绿色的锁定图标。

自动更新让我们加密SSL证书
让我们加密的证书有效期为90天。 要在证书过期之前自动更新证书,我们将创建一个cronjob,该证书每天运行两次,并在证书过期前30天自动更新任何证书。
运行
crontab
命令来创建一个新的cronjob,它将更新证书,创建一个包含DH密钥的新组合文件,然后重新启动apache:
sudo crontab -e
0 */12 * * * root test -x /usr/bin/certbot -a \! -d /run/systemd/system && perl -e 'sleep int(rand(3600))' && certbot -q renew --renew-hook "systemctl reload
保存并关闭文件。
要测试续订过程,可以使用certbot命令,然后使用
--dry-run
开关:
sudo certbot renew --dry-run
如果没有错误,则表示更新过程成功。
结论
在本教程中,您使用了“让我们加密”客户端certbot为您的域下载SSL证书。 您还创建了Apache代码段以避免重复代码,并配置了Apache以使用证书。 在本教程的最后,您已经设置了cronjob来自动更新证书。
让我们加密certbot ssl这篇文章是在CentOS 7系列上安装LAMP堆栈的一部分。
本系列的其他文章:
•如何在CentOS 7上安装Apache•在CentOS 7上安装MySQL•如何在CentOS 7上设置Apache虚拟主机•在CentOS 7上通过加密让Apache安全让我们在centos 7上加密来保护nginx
在本教程中,我们将提供有关如何使用CentOS 7上的certbot工具通过Let's Encrypt保护Nginx的逐步说明。
让我们在centos 8上加密来保护Apache
本教程说明了如何在运行Apache作为Web服务器的CentOS 8上安装免费的Let's Encrypt SSL证书。 我们将使用certbot工具获取并更新证书。
让我们在centos 8上加密来保护nginx
在本教程中,我们将提供有关如何在运行Nginx作为Web服务器的CentOS 8上安装免费的Let's Encrypt SSL证书的分步说明。 我们还将展示如何配置Nginx以使用SSL证书并启用HTTP / 2。







