三二互联专业提供速度最快最稳定的美国服务器、香港服务器。中美直连,亚洲优化![ 代理登陆 ] [ 付款方式 ] [ 找回密码 ][ 电子协议责任书 ]
硬件资源保障

采用高配品牌服务器

主流强悍CPU配置

确保服务高速稳定运行

中美直连线路

中美直连亚洲优化

采用中国CN2骨干网络

保证速度飞快稳定高效

服务器如何启用网站 WAF 防火墙?

美国、香港服务器

服务器如何启用网站 WAF 防火墙?

04-13   来源:

 一、宝塔面板一键开启(推荐)

适用于 Nginx,5 分钟完成。
登录宝塔 → 软件商店 → 找到 Nginx → 设置 → 配置修改。
在 http { ... } 区块找到 #include luawaf.conf;,删除行首 # 改为 include luawaf.conf;。
保存并重启 Nginx(不是重载)。
验证:访问 http://你的域名/?id=../etc/passwd,应返回 403 拦截。
配置规则:文件管理进入 /www/server/nginx/waf,编辑 config.lua,开启攻击日志、调整误杀策略。
安全组放行 80/443,宝塔 WAF 设置中开启 SQL 注入、XSS 等规则。
二、Nginx 手动启用 ModSecurity + OWASP CRS
适用于无宝塔场景,防护更全面。
1. 安装依赖
bash
运行
# Ubuntu/Debian
apt update && apt install -y libmodsecurity3 libnginx-mod-http-modsecurity
# CentOS/RHEL
yum install -y mod_security nginx-mod-http-modsecurity
2. 启用模块
编辑 Nginx 主配置(通常 /etc/nginx/nginx.conf),在 http 块添加:
nginx
load_module modules/ngx_http_modsecurity_module.so; # 确保存在
http {
    modsecurity on;
    modsecurity_rules_file /etc/nginx/modsec/main.conf;
    # 其他配置...
}
3. 配置 OWASP CRS(核心规则集)
bash
运行
# 创建目录
mkdir -p /etc/nginx/modsec/crs
# 下载规则
git clone https://github.com/coreruleset/coreruleset /etc/nginx/modsec/crs
cd /etc/nginx/modsec/crs
git checkout v4.0/stable # 稳定分支
# 复制配置
cp crs-setup.conf.example crs-setup.conf
# 生成主配置
tee /etc/nginx/modsec/main.conf <
Include /etc/nginx/modsec/modsecurity.conf
Include /etc/nginx/modsec/crs/crs-setup.conf
Include /etc/nginx/modsec/crs/rules/*.conf
EOF
4. 调整配置(按需)
编辑 /etc/nginx/modsec/modsecurity.conf:
ini
SecRuleEngine On          # On=拦截,DetectionOnly=仅检测
SecAuditLog /var/log/nginx/modsec_audit.log
SecAuditLogParts ABIJDEFHZ
5. 重启与验证
bash
运行
nginx -t # 检查配置语法
systemctl restart nginx
# 测试拦截
curl -I "http://你的域名/?id=1" OR 1=1--"
# 应返回 HTTP/1.1 403 Forbidden
三、Apache 手动启用 ModSecurity + OWASP CRS
1. 安装模块
bash
运行
# Ubuntu/Debian
apt update && apt install -y libapache2-mod-security2
a2enmod security2
# CentOS/RHEL
yum install -y mod_security mod_security_crs httpd
2. 配置规则
bash
运行
cp /etc/modsecurity/modsecurity.conf-recommended /etc/modsecurity/modsecurity.conf
sed -i "s/SecRuleEngine DetectionOnly/SecRuleEngine On/" /etc/modsecurity/modsecurity.conf
3. 启用并重启
bash
运行
# Ubuntu/Debian
systemctl restart apache2
# CentOS/RHEL
systemctl restart httpd
四、关键配置与验证
表格
项目 操作 路径 / 命令
日志路径 查看拦截日志 宝塔:/www/wwwlogs/waf/;Nginx/Apache:/var/log/nginx/modsec_audit.log / /var/log/modsec_audit.log
误杀处理 白名单 / 排除 宝塔 WAF 规则组排除;ModSecurity 用 SecRuleRemoveById
安全组 放行必要端口 80、443、自定义 SSH 端口
测试 触发拦截 curl -I "http://域名/?xss=alert(1)"
五、常见问题与加固
开启后站点异常:先设 SecRuleEngine DetectionOnly,查日志定位误报并添加排除规则。
性能优化:启用缓存、调整规则级别,优先放行业务白名单。
定期更新规则与系统补丁,配合 Fail2ban 防御暴力破解。

三二互联专业提供香港VPS,美国VPS主机,香港云服务器租用等业务香港美国到大陆CN2 GIA速度最快

上一篇:如何安装ModSecurity和OWASP CRS? 下一篇:如何进行漏洞修复?

美国GIA服务器三二互联版权所有 WWW.250.cc 2008-2015 All Rights Reserved
三二互联 - 专业的美国C3服务器香港vps、抗DOOS流量清洗、云备份系统、网站加速系统、美国GIA服务器和香港云服务器产品提供商
三二互联24小时在线工单系统为您提供全面、专业、周到的技术支持与服务
咨询热线:400-679-9994(免长话费)