在CentOS系統上為Apache服務器配置SSL證書的步驟如下:
yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
yum install mod_ssl
yum install python-certbot-apache
/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>
sudo certbot --apache -d example.com
按照提示操作,完成證書安裝。
crontab -e
添加以下行:
0 1 * * * /usr/bin/certbot renew >> /var/log/ssl-renew.log 2>&1
這將在每月1日的中午12點自動執行續訂命令。
firewall-cmd --zone=public --add-port=443/tcp --permanent
firewall-cmd --reload
systemctl restart httpd
https://example.com
,如果地址欄出現鎖的圖標,說明SSL證書安裝成功。請注意,上述步驟中的路徑和文件名需要根據您的實際情況進行替換。如果您使用的是Let’s Encrypt證書,證書文件通常位于/etc/letsencrypt/live/example.com/
目錄下。此外,確保您的防火墻允許443端口的流量,以便Apache能夠正常處理HTTPS請求。