在Ubuntu上優化Apache2的SSL設置可以提高網站的安全性和性能。以下是一些常見的優化步驟:
首先,確保你的系統和Apache2都是最新的:
sudo apt update
sudo apt upgrade
你可以使用Let’s Encrypt免費獲取SSL證書。安裝Certbot并獲取證書:
sudo apt install certbot python3-certbot-apache
sudo certbot --apache -d yourdomain.com -d www.yourdomain.com
按照提示完成證書的獲取和配置。
編輯Apache2的SSL配置文件 /etc/apache2/sites-available/default-ssl.conf
:
sudo nano /etc/apache2/sites-available/default-ssl.conf
確保以下設置:
<VirtualHost *:443>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
SSLEngine on
SSLCertificateFile /etc/letsencrypt/live/yourdomain.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/yourdomain.com/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
# 優化SSL設置
SSLProtocol all -SSLv2 -SSLv3
SSLCipherSuite HIGH:!aNULL:!MD5
SSLHonorCipherOrder on
SSLCompression off
SSLSessionCache shared:SSL:10m
SSLSessionTickets off
# 啟用OCSP Stapling
OCSPUseStapling on
OCSPStaplingResponseCache shmcb:/var/run/ocsp-stapling-cache(128000)
# 啟用HSTS
Header always set Strict-Transport-Security "max-age=31536000; includeSubDomains"
<Directory /var/www/html>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
確保SSL站點已啟用:
sudo a2ensite default-ssl
應用配置更改:
sudo systemctl restart apache2
定期檢查Apache2的錯誤日志和訪問日志,以確保SSL配置正常工作:
sudo tail -f /var/log/apache2/error.log
sudo tail -f /var/log/apache2/access.log
default-ssl.conf
中添加以下行:Protocols h2 http/1.1
通過以上步驟,你可以顯著提高Ubuntu上Apache2的SSL設置的安全性和性能。