以下是在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。
参考来源: