Nginx+Naxsi部署专业级Web应用防火墙
Naxsi简介:
Naxsi是一个开放源代码、高效、低维护规则的Nginx web应用防火墙模块。Naxsi的主要目标是帮助人们加固他们的web应用程序,以抵御SQL注入、跨站脚本、跨域伪造请求、本地和远程文件包含漏洞。
安装配置naxsi模块步骤如下:
一.首先要搭建lnmp环境并添加lua模块:
添加lua模块步骤如下:
1.下载并安装lua模块:
wget http://luajit.org/download/LuaJIT-2.0.1.tar.gz
tar zxvfLuaJIT-2.0.1.tar.gz
cd LuaJIT-2.0.1
make && make install
2.下载ngx_devel_kit 和nginx_lua_module并解压
tar zxvfngx_devel_kit-0.2.19.tar.gz
tar zxvflua-nginx-module-0.9.2.tar.gz
3.进入nginx源码文件夹,编译安装nginx
a.导入环境变量
export LUAJIT_LIB=/usr/local/lib
export LUAJIT_INC=/usr/local/include/luajit-2.0
b.查看nginx的先前的configure配置
/usr/local/webserver/nginx/sbin/nginx -V
nginxversion: nginx/1.2.9
configurearguments: --user=www --group=www --prefix=/usr/local/webserver/nginx --with- http_stub_status_module --with-http_ssl_module
c.重新编译安装nginx:
cd /tools/nginx-1.2.9
./configure --user=www --group=www --prefix=/usr/local/webserver/nginx --with-http_stub_status_module --with-http_ssl_module --add-module=/tools/ngx_devel_kit-0.2.19 --add-module=/tools/lua-nginx-module-0.9.2
make -j2
make install
此时检查nginx配置文件语法会出现错误:
/usr/local/webserver/nginx/sbin/nginx -t
/usr/local/webserver/nginx/sbin/nginx:error while loading shared libraries:
libluajit-5.1.so.2: cannot open sharedobject file: No such file or directory
原因是找不到libluajit-5.1.so.2
解决方法:
find / -name "libluajit-5.1.so.2"
/usr/local/lib/libluajit-5.1.so.2
echo "/usr/local/lib" >>/etc/ld.so.conf
ldconfig
/usr/local/webserver/nginx/sbin/nginx -t
nginx:the configuration file /usr/local/webserver/nginx/conf/nginx.conf syntax is ok
nginx:configuration file /usr/local/webserver/nginx/conf/nginx.conf test issuccessful
配置OK。
二.下载naxsi模块:
wget http://naxsi.googlecode.com/files/naxsi-core-0.50.tgz
tar zxvf naxsi-core-0.50.tgz
三.关联naxsi模块:
先查看nginx的原有./configure配置,然后复制后并添加naxsi模块的路径:
cd /tools/nginx-1.2.9
./configure --user=www --group=www --prefix=/usr/local/webserver/nginx --with-http_stub_status_module --with-http_ssl_module --add-module=/tools/ngx_devel_kit-0.2.19 --add-module=/tools/lua-nginx-module-0.9.2 --add-module=/tools/naxsi-core-0.50/naxsi_src/
make && make install
Nginx 的详细介绍:请点这里
Nginx 的下载地址:请点这里
推荐阅读: