如何在CentOS 8/RHEL 8上的Apache中配置Let's Encrypt SSL证书

时间:2020-03-21 11:42:59  来源:igfitidea点击:

Let's Encrypt是免费的SSL证书提供商,由非营利组织“ ISRG”创建。
最重要的是它免费为我们提供了免费。
添加此SSL证书后,现在使用HTTPS协议。

该证书通过为提供免费的SSL证书来确保网络安全。
要实现这些SSL证书,请考虑遵循本教程中的所有步骤。

步骤1(安装Apache Web服务器)

使用DNF软件包安装程序安装Apache Web Server

# dnf install httpd*

启动httpd服务

# systemctl start httpd

在启动期间启用httpd服务。

# systemctl enable httpd

添加FQDN和服务器IP地址

# vim /etc/hosts

使用FQDN和IP地址编辑行

127.0.0.1 theitroad.com
::1 theitroad.com
步骤2(配置Apache配置文件)
# vim /etc/httpd/conf/httpd.conf

添加给定的行

IncludeOptional setup/*.conf

在Apache Web服务器上添加虚拟主机
创建目录

# mkdir /etc/httpd/setup

添加虚拟主机

# vim /etc/httpd/setup/theitroad.com.conf

将给定的行添加到配置文件

<VirtualHost *:80>
ServerName theitroad.com
ServerAlias theitroad.com
DocumentRoot /var/www/
</VirtualHost>

重新启动Apache服务

# systemctl restart httpd

启用EPEL储存库

# wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
# rpm -ivh epel-release-latest-8.noarch.rpm

安装在安装过程中所需的Pre依赖项

# dnf install git python-pip
步骤3(使用“Let’s Encrypt ”生成免费的SSL证书)

从GITHUB克隆Let's Encrypt源代码

# git clone https://github.com/letsencrypt/letsencrypt

更改目录以加密目录

# cd letsencrypt/

注意:在开始安装之前,请使用域DNS地址仪表板在DNS A记录上添加具有正确IP地址的域名,并检查防火墙允许的端口443和80端口(白名单)。

# ./letsencrypt-auto --apache -d theitroad.com --verbose

添加电子邮件ID以恢复丢失的密钥。

接受服务条款。

之后,请按一下nag屏幕上的步骤以完成Let’s Encrypt 祝贺屏幕。

步骤4(成功生成SSL证书后,将其添加到Apache虚拟主机配置文件中)
# vim /etc/httpd/setup/theitroad.com.conf

将给定行添加到配置文件的最后一行

<VirtualHost *:443>
ServerName theitroad.com
ServerAlias theitroad.com
DocumentRoot /var/www/
SSLEngine on
SSLCertificateFile /etc/letsencrypt/live/theitroad.com/cert.pem
SSLCertificateKeyFile /etc/letsencrypt/live/theitroad.com/privkey.pem
SSLCertificateChainFile /etc/letsencrypt/live/theitroad.com/chain.pem
</VirtualHost>

编辑Apache SSL配置文件

# vim /etc/httpd/conf.d/ssl.conf

添加这些

SSLCertificateFile /etc/letsencrypt/live/theitroad.com/cert.pem
SSLCertificateKeyFile /etc/letsencrypt/live/theitroad.com/privkey.pem
SSLCertificateChainFile /etc/letsencrypt/live/theitroad.com/chain.pem

检查“Let’s Encrypt ”生成的虚拟主机

# cat /etc/httpd/conf.d/vhost-theitroad.com-le-ssl.conf

最后重启Apache服务

# systemctl restart httpd
第5步(在90天之前更新加密算法)

SSL证书的有效期为90天,之后我们需要通过运行给定的脚本来更新它们

# ./letsencrypt-auto renew

我们可以在HTTPS上检查域SSL配置
'https://www.ssllabs.com/ssltest/analyze.html'

有关更多信息,我们可以访问Let's Encrypt官方。

我们已经在CentOS和RHEL上为Apache配置了Lets Encrypt SSL 。