在Debian系统上配置Apache以使用SSL证书的步骤如下:
sudo apt update
sudo apt install certbot python3-certbot-apache
sudo openssl dhparam -out /etc/ssl/certs/dhparam.pem 2048
sudo certbot certonly --agree-tos --email admin@example.com --webroot -w /var/lib/letsencrypt/ -d example.com -d www.example.com
其中,example.com
应替换为您的域名。
创建或编辑虚拟主机配置文件,通常位于 /etc/apache2/sites-available/
目录下,例如 example.com.conf
。
在配置文件中添加以下内容:
<VirtualHost *: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
</VirtualHost>
example.com
为您的域名,并确保 DocumentRoot
指向您的网站根目录。sudo a2ensite example.com.conf
sudo systemctl reload apache2
ufw
):sudo ufw allow 'Apache Full'
在浏览器中访问 https://example.com
,确保显示安全连接。
请注意,上述步骤假设您已经拥有了一个域名,并且该域名已经解析到运行Apache的服务器IP地址上。如果您使用的是Let’s Encrypt证书,证书通常是免费的,并且会自动更新,但您需要定期使用Certbot进行续期。此外,根据您的具体需求,您可能需要调整防火墙规则和其他安全设置。
辰迅云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读: cpustat如何帮助优化Debian服务器