以下是在Ubuntu上安全配置Apache2的關鍵步驟:
系統更新與基礎配置
sudo apt update && sudo apt upgrade。/etc/apache2/apache2.conf,設置ServerTokens Prod和ServerSignature Off。Options -Indexes。防火墻與端口管理
sudo ufw allow 'Apache Full',僅開放HTTP/HTTPS端口。SSL/TLS加密
sudo a2enmod ssl。/etc/apache2/sites-available/default-ssl.conf,指定證書路徑。模塊與權限管理
sudo a2dismod 模塊名(如autoindex)。/etc/apache2/envvars中APACHE_RUN_USER和APACHE_RUN_GROUP為www-data。sudo chown -R www-data:www-data /var/www/html,目錄權限設為755,文件設為644。安全模塊與日志監控
mod_evasive,設置請求限制參數。/var/log/apache2/error.log和access.log,及時發現異常。高級加固
完成配置后,重啟Apache服務:sudo systemctl restart apache2。
參考來源: