阅读量:317
在CentOS系统上为Apache服务器配置SSL证书的步骤如下:
安装EPEL源:
yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
安装mod_ssl模块:
yum install mod_ssl
安装Certbot客户端:
yum install python-certbot-apache
虚拟主机配置:在/etc/httpd/conf.d/目录下创建或编辑虚拟主机配置文件,例如example.com.conf:
:80 >
ServerName example.com
DocumentRoot "/var/www/html"
:443 >
ServerName example.com
DocumentRoot "/var/www/html"
SSLEngine on
SSLCertificateFile "/path/to/your/certificate.crt"
SSLCertificateKeyFile "/path/to/your/private.key"
SSLCertificateChainFile "/path/to/your/chainfile.crt"
"/var/www/html" >
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
获取并配置SSL证书:使用Certbot为Apache生成SSL证书:
sudo certbot --apache -d example.com
按照提示操作,完成证书安装。
自动续订证书:编辑crontab文件以设置自动续订:
crontab -e
添加以下行:
0 1 * * * /usr/bin/certbot renew >> /var/log/ssl-renew.log 2>&1
这将在每月1日的中午12点自动执行续订命令。
开放端口:确保443端口已开放:
firewall-cmd --zone=public --add-port=443/tcp --permanent
firewall-cmd --reload
重启Apache服务:重启Apache以应用更改:
systemctl restart httpd
验证SSL证书安装:在浏览器中访问,如果地址栏出现锁的图标,说明SSL证书安装成功。
请注意,上述步骤中的路径和文件名需要根据您的实际情况进行替换。如果您使用的是Let’s Encrypt证书,证书文件通常位于/etc/letsencrypt/live/example.com/目录下。此外,确保您的防火墙允许443端口的流量,以便Apache能够正常处理HTTPS请求。