阅读量:266
在Debian系统上配置Apache以使用SSL证书的步骤如下:
安装Certbot和Apache SSL模块:
sudo apt update
sudo apt install certbot python3-certbot-apache
生成2048位DH密钥(如果尚未生成):
sudo openssl dhparam -out /etc/ssl/certs/dhparam.pem 2048
获取Let’s Encrypt SSL证书:
sudo certbot certonly --agree-tos --email admin@example.com --webroot -w /var/lib/letsencrypt/ -d example.com -d www.example.com
其中,example.com应替换为您的域名。
配置Apache:
:443 >
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/example.com/public_html
ErrorLog ${APACHE_LOG_DIR}/example.com-error.log
CustomLog ${APACHE_LOG_DIR}/example.com-access.log combined
SSLEngine on
SSLCertificateFile /etc/letsencrypt/live/example.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem
SSLCertificateChainFile /etc/letsencrypt/live/example.com/chain.pem
# 可选:启用HTTP/2
SSLProtocol all -SSLv3 -TLSv1 -TLSv1.1
SSLCipherSuite HIGH:!aNULL:!MD5:!ADH:!RC4:!DH:!RSA
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"
SSLCompression off
SSLUseStapling on
SSLStaplingCache "shmcb:logs/stapling-cache(150000)"
SSLSessionTickets off
启用新的虚拟主机配置文件:
sudo a2ensite example.com.conf
重新加载Apache配置:
sudo systemctl reload apache2
配置防火墙(如果使用 ufw):
sudo ufw allow 'Apache Full'
测试SSL证书:
在浏览器中访问 ,确保显示安全连接。
请注意,上述步骤假设您已经拥有了一个域名,并且该域名已经解析到运行Apache的服务器IP地址上。如果您使用的是Let’s Encrypt证书,证书通常是免费的,并且会自动更新,但您需要定期使用Certbot进行续期。此外,根据您的具体需求,您可能需要调整防火墙规则和其他安全设置。