Debian Apache SSL证书配置方法
以下是在Debian系统上配置Apache SSL证书的步骤:
-
安装Apache和SSL模块
sudo apt update sudo apt install apache2 sudo a2enmod ssl # 启用SSL模块
-
获取SSL证书
- Let’s Encrypt免费证书(推荐):
按提示完成证书申请,Certbot会自动配置Apache。sudo apt install certbot python3-certbot-apache sudo certbot --apache -d yourdomain.com -d www.yourdomain.com
- 自签名证书(仅测试用):
sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 \ -keyout /etc/ssl/private/apache-selfsigned.key \ -out /etc/ssl/certs/apache-selfsigned.crt
- Let’s Encrypt免费证书(推荐):
-
配置Apache虚拟主机
编辑配置文件(如/etc/apache2/sites-available/yourdomain.com.conf
)::443> ServerName yourdomain.com DocumentRoot /var/www/yourdomain.com SSLEngine on SSLCertificateFile /etc/letsencrypt/live/yourdomain.com/fullchain.pem # Let’s Encrypt证书路径 SSLCertificateKeyFile /etc/letsencrypt/live/yourdomain.com/privkey.pem # 可选:启用HTTP/2、安全头等 # SSLProtocol all -SSLv3 -TLSv1 -TLSv1.1 # Header always set Strict-Transport-Security "max-age=63072000" 若使用自签名证书,需将
SSLCertificateFile
和SSLCertificateKeyFile
指向生成的.crt
和.key
文件。 -
启用站点并重启服务
sudo a2ensite yourdomain.com.conf # 启用配置文件 sudo systemctl restart apache2 # 重启Apache
-
验证配置
- 浏览器访问
https://yourdomain.com
,检查是否显示安全锁图标。 - 使用命令
sudo apache2ctl configtest
测试配置语法是否正确。
- 浏览器访问
-
可选:强制HTTP跳转HTTPS
编辑HTTP虚拟主机配置文件(如/etc/apache2/sites-available/000-default.conf
),添加重定向规则::80> ServerName yourdomain.com Redirect permanent / https://yourdomain.com/ 重启Apache后生效。
说明:
- Let’s Encrypt证书需定期续期,可使用
sudo certbot renew --dry-run
测试自动续期功能。 - 生产环境中建议使用受信任CA的证书,并配置强加密套件(如
ECDHE-RSA-AES256-GCM-SHA384
)。
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权请联系我们,一经查实立即删除!