centos apache SSL证书怎么配置

420
2025/2/22 21:31:58
栏目: 云计算
开发者测试专用服务器限时活动,0元免费领,库存有限,领完即止! 点击查看>>

在CentOS系统上为Apache服务器配置SSL证书的步骤如下:

  1. 安装EPEL源
yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
  1. 安装mod_ssl模块
yum install mod_ssl
  1. 安装Certbot客户端
yum install python-certbot-apache
  1. 虚拟主机配置: 在/etc/httpd/conf.d/目录下创建或编辑虚拟主机配置文件,例如example.com.conf
<VirtualHost *:80>
    ServerName example.com
    DocumentRoot "/var/www/html"
</VirtualHost>

<VirtualHost *: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"

    <Directory "/var/www/html">
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>
  1. 获取并配置SSL证书: 使用Certbot为Apache生成SSL证书:
sudo certbot --apache -d example.com

按照提示操作,完成证书安装。

  1. 自动续订证书: 编辑crontab文件以设置自动续订:
crontab -e

添加以下行:

0 1 * * * /usr/bin/certbot renew >> /var/log/ssl-renew.log 2>&1

这将在每月1日的中午12点自动执行续订命令。

  1. 开放端口: 确保443端口已开放:
firewall-cmd --zone=public --add-port=443/tcp --permanent
firewall-cmd --reload
  1. 重启Apache服务: 重启Apache以应用更改:
systemctl restart httpd
  1. 验证SSL证书安装: 在浏览器中访问https://example.com,如果地址栏出现锁的图标,说明SSL证书安装成功。

请注意,上述步骤中的路径和文件名需要根据您的实际情况进行替换。如果您使用的是Let’s Encrypt证书,证书文件通常位于/etc/letsencrypt/live/example.com/目录下。此外,确保您的防火墙允许443端口的流量,以便Apache能够正常处理HTTPS请求。

辰迅云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>

推荐阅读: centos更新内核后无法启动如何解决