改版ngx_lua_waf防护Nginx(WAF防火墙)

mtain 2020年02月16日 476次浏览

安装过程

yum install wget gcc gcc-c++ pcre pcre-devel openssl openssl-devel zlib zlib-devel

cd /opt



wget https://github.com/simplresty/ngx_devel_kit/archive/v0.3.1rc1.tar.gz
tar xf v0.3.1rc1.tar.gz


wget https://github.com/openresty/lua-nginx-module/archive/v0.10.14.tar.gz
tar xf v0.10.14.tar.gz


安装luajit
wget https://github.com/openresty/luajit2/archive/v2.1-20190329.tar.gz
tar xf v2.1-20190329.tar.gz
cd luajit2-2.1-20190329
make
make install

cd ..
rm -r luajit2-2.1-20190329* v2.1-20190329.tar.gz



配置luajit环境变量
vim + /etc/profile

export LUAJIT_LIB=/usr/local/lib
export LUAJIT_INC=/usr/local/include/luajit-2.1

source /etc/profile


useradd -s /bin/false -M www

wget http://nginx.org/download/nginx-1.14.2.tar.gz
tar xf nginx-1.14.2.tar.gz


./configure --user=www --group=www --prefix=/opt/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_v2_module --with-http_gzip_static_module --with-http_sub_module --add-module=/opt/ngx_devel_kit-0.3.1rc1 --add-module=/opt/lua-nginx-module-0.10.14 --with-ld-opt=-Wl,-rpath,$LUAJIT_LIB
make
make install




cd /opt/nginx/conf
wget https://github.com/whsir/ngx_lua_waf/archive/v1.0.3.tar.gz
tar xf v1.0.3.tar.gz
mv ngx_lua_waf-1.0.3/ waf



vim /opt/nginx/conf/nginx.conf

在http{}中 添加

lua_package_path "/opt/nginx/conf/waf/?.lua";
lua_shared_dict limit 10m;
init_by_lua_file  /opt/nginx/conf/waf/init.lua;
access_by_lua_file /opt/nginx/conf/waf/waf.lua;



修改config.lua中的路径改为/usr/local/opt
attacklog = "on"

mkdir /opt/nginx/logs/hack
chown -R www:www /opt/nginx

最后启动nginx

参考博客

改版作者博客
https://blog.whsir.com/post-4141.html

改良版
https://github.com/whsir/ngx_lua_waf

原版
https://github.com/loveshell/ngx_lua_waf

其它改版

强烈推荐: https://github.com/unixhot/waf.git

OpenResty 最佳实践

https://www.bookstack.cn/read/openresty-best-practices/README.md

modsecurity模块防护Nginx

Nginx1.14.0+ModSecurity实现简单的WAF:https://www.cnblogs.com/xll970105/p/10250697.html

nginx增加modsecurity模块:https://blog.csdn.net/cheng_fangang/article/details/50722770