阅读量:86
以下是在CentOS中防止Apache2被攻击的关键措施:
-
系统与软件更新
定期更新系统和Apache软件包,修补已知漏洞:sudo yum update -y -
配置防火墙
使用firewalld限制仅开放HTTP(80)和HTTPS(443)端口:sudo firewall-cmd --permanent --add-service=http sudo firewall-cmd --permanent --add-service=https sudo firewall-cmd --reload -
禁用不必要的模块
编辑/etc/httpd/conf/httpd.conf,关闭不需要的模块(如mod_rewrite等):# 示例:禁用重写引擎 RewriteEngine Off -
启用安全模块
- mod_security:安装并配置规则集(如OWASP CRS)检测恶意请求。
- mod_evasive:限制DDoS攻击,配置请求频率限制。
-
隐藏敏感信息
- 修改
httpd.conf隐藏Apache版本和签名:ServerTokens Prod ServerSignature Off - 禁止目录列表:
Options -Indexes
- 修改
-
强化认证与加密
- 使用强密码,通过
.htaccess或配置文件限制访问。 - 配置SSL/TLS证书启用HTTPS,保护数据传输。
- 使用强密码,通过
-
权限与资源控制
- 以专用用户(如
www-data)运行Apache,限制文件权限:sudo chown -R www-data:www-data /var/www/html sudo chmod -R 755 /var/www/html - 限制上传文件大小、请求速率等。
- 以专用用户(如
-
日志与监控
启用详细日志记录,定期分析异常行为:LogLevel warn ErrorLog /var/log/httpd/error_log CustomLog /var/log/httpd/access_log combined -
DDoS防护
- 使用
mod_ratelimit限制IP请求速率。 - 部署第三方防护服务(如Cloudflare)应对大规模攻击。
- 使用
-
定期审计与备份
定期扫描配置漏洞,备份配置文件以便快速恢复。
参考来源: