nginx_waf(LTS)的使用

467 字
2 分钟
nginx_waf(LTS)的使用

nginx配置文件nginx.conf 加入cf ip

http
{
#real ip 必须,为了cf回源不被封
set_real_ip_from 103.21.244.0/22;
set_real_ip_from 103.22.200.0/22;
set_real_ip_from 103.31.4.0/22;
set_real_ip_from 108.162.192.0/18;
set_real_ip_from 131.0.72.0/22;
set_real_ip_from 141.101.64.0/18;
set_real_ip_from 162.158.0.0/15;
set_real_ip_from 172.64.0.0/13;
set_real_ip_from 173.245.48.0/20;
set_real_ip_from 188.114.96.0/20;
set_real_ip_from 190.93.240.0/20;
set_real_ip_from 197.234.240.0/22;
set_real_ip_from 198.41.128.0/17;
set_real_ip_from 2400:cb00::/32;
set_real_ip_from 2606:4700::/32;
set_real_ip_from 2803:f800::/32;
set_real_ip_from 2405:b500::/32;
set_real_ip_from 2405:8100::/32;
set_real_ip_from 2c0f:f248::/32;
set_real_ip_from 2a06:98c0::/29;
set_real_ip_from 104.16.0.0/13;
set_real_ip_from 104.24.0.0/14;
set_real_ip_from 172.20.10.11;
real_ip_header CF-Connecting-IP;
real_ip_recursive on;
#real ip
}

http: nginx.conf可加入(这lts版本的用法)

http{
#nginx_waf模块
# on/off 表示启用和关闭
waf on;
# 规则文件所在目录的绝对路径,必须以/结尾
waf_rule_path /usr/local/src/ngx_waf/assets/rules/;
# 防火墙工作模式,STD表示标准模式,DYNAMIC功能更多包含cookie
waf_mode STD;
# CC防御参数
# 30表示每分钟请求次数上限,超出上限后封禁对应ip地址60分钟
waf_cc_deny rate=1000r/m duration=1h;
# 对除了IP黑白名单检测、CC防护和POST检测以外的所有检测生效
waf_cache capacity=50;
#设置优先级
waf_priority "W-IP IP CC W-URL UNDER-ATTACK URL ARGS UA W-REFERER REFERER COOKIE ADV";
#nginx_waf模块
}

server (单网址下) nginx.conf加入(这lts版本的用法)

server{
#nginx_waf模块
# on/off 表示启用和关闭
waf on;
# 规则文件所在目录的绝对路径,必须以/结尾
waf_rule_path /usr/local/src/ngx_waf/assets/rules/;
# 防火墙工作模式,STD表示标准模式,DYNAMIC功能更多包含cookie
waf_mode STD;
# CC防御参数
# 120r表示每分钟请求次数上限,超出上限后封禁对应ip地址1h
waf_cc_deny rate=120r/m duration=1h;
# 检测100个名单,对除了IP黑白名单检测、CC防护和POST检测以外的所有检测生效
waf_cache capacity=100;
#设置优先级
waf_priority "W-IP IP CC W-URL UNDER-ATTACK URL ARGS UA W-REFERER REFERER COOKIE ADV";
waf_http_status cc_deny=444;
waf_under_attack off uri=/404.html; #这个感觉没啥用?
# 将静态资源的请求速率限制到 10,000 次/分钟。
location /static/ {
waf_cc_deny rate=10000r/m duration=720h;
}
# 将动态资源的请求速率限制到 2,000 次/分钟。
location /dynamic/ {
waf_cc_deny rate=2000r/m duration=720h;
}
#nginx_waf模块
}

以上

文章分享

如果这篇文章对你有帮助,欢迎分享给更多人!

nginx_waf(LTS)的使用
https://blog.qiui.net/posts/2025-05-30-nginx-waf-lts-26/
作者
Q
发布于
2025-05-30
许可协议
CC BY-NC-SA 4.0
随机文章随机推荐

评论区

Profile Image of the Author
Qiui
搞点好玩的.
公告
欢迎来到我的博客!这是一则示例公告。
分类
标签

文章目录