官方git地址:https://github.com/ADD-SP/ngx_waf
官方文档:https://docs.addesp.com/ngx_waf/zh-cn/
他是配合ModSecurity使用的,编译时直接加入--add-module=/usr/local/nginxmodule/ngx_waf
创建插件目录和用户

mkdir -p /usr/local/nginxmodule;
groupadd www&&useradd -m -s /sbin/nologin -g www www;

下载ngx_waf和其它组件

git clone -b current https://github.com/ADD-SP/ngx_waf.git
mv ngx_waf /usr/local/nginxmodule
wget https://github.com/maxmind/libmaxminddb/releases/download/1.6.0/libmaxminddb-1.6.0.tar.gz -O libmaxminddb.tar.gz
mkdir -p libmaxminddb
tar -zxf "libmaxminddb.tar.gz" -C libmaxminddb --strip-components=1
cd libmaxminddb
./configure --prefix=/usr/local/libmaxminddb
make -j4&&make install
cd -
git clone -b v3.0.5 https://github.com/SpiderLabs/ModSecurity.git
cd ModSecurity
chmod +x build.sh
./build.sh
git submodule init
git submodule update
./configure --prefix=/usr/local/modsecurity --with-maxmind=/usr/local/libmaxminddb
make -j4&&make install
export LIB_MODSECURITY=/usr/local/modsecurity
cd /usr/local/nginxmodule/ngx_waf
git clone -b v1.7.15 https://github.com/DaveGamble/cJSON.git lib/cjson
git clone -b v2.3.0 https://github.com/troydhanson/uthash.git lib/uthash
cd -
git clone https://github.com/jedisct1/libsodium.git --branch stable libsodium-src
cd libsodium-src
./configure --prefix=/usr/local/libsodium --with-pic
make -j4&& make install
export LIB_SODIUM=/usr/local/libsodium
cd /usr/local/nginxmodule/ngx_waf
make
cd -
cd /usr/local
git clone https://github.com/troydhanson/uthash.git
export LIB_UTHASH=/usr/local/uthash
cd /usr/local/nginxmodule/ngx_waf
git clone https://github.com/libinjection/libinjection.git inc/libinjection
cd /usr/local/nginxmodule/ngx_waf/inc/libinjection
./autogen.sh
./configure
make -j4
cd -

下载nginx

wget https://nginx.org/download/nginx-1.22.1.tar.gz
tar zxf nginx-1.22.1.tar.gz
cd nginx-1.22.1
./configure 以前的参数 --add-module=/usr/local/nginxmodule/ngx_waf
make -j4&&make install

编辑nginx.conf在http段加入以下内容

waf_zone name=waf size=20m;

在每个主机的server{}括号内写入以下内容

waf on; # on 表示启用,off 表示关闭。
# 规则文件所在目录的绝对路径,必须以 / 结尾。
waf_rule_path /usr/local/nginxmodule/ngx_waf/assets/rules/;
# 防火墙工作模式,STD 表示标准模式。
waf_mode STD;
# CC 防御参数,1000 每分钟请求次数上限,超出上限后封禁对应 ip 60 分钟。
waf_cc_deny on rate=1000r/m duration=60m zone=waf:cc;
# 最多缓存 50 个检测目标的检测结果,对除了 IP 黑白名单检测、CC 防护和 POST 检测以外的所有检测生效。
waf_cache on capacity=50;
分类: nginx使用方法 标签: 暂无标签

评论

暂无评论数据

暂无评论数据

目录