nginx + naxsi firewall howto
What is naxsi?
Naxsi is an open source, high performance, low rules maintenance, Web Application Firewall module for Nginx.
From 3th april 2012 in debian repository called dotdeb.org there is debian package called nginx-naxsi , but now we will install and configure with source because of change the server_tokens π
First:
cd /usr/src/ wget "http://nginx.org/download/nginx-1.1.19.tar.gz" wget "http://naxsi.googlecode.com/files/naxsi-0.44-1.tgz" tar zxvf nginx-1.1.19.tar.gz tar zxvf naxsi-0.44-1.tgz cd nginx-1.1.19 ./configure --add-module=../naxsi-0.44-1/naxsi_src/Β --prefix=/usrΒ Β --sbin-path=/usr/sbin/nginxΒ Β --conf-path=/etc/nginx/nginx.confΒ Β --error-log-path=/var/log/nginx/error.logΒ Β --pid-path=/var/run/nginx/nginx.pidΒ Β Β --lock-path=/var/lock/nginx.lockΒ Β --user=nginxΒ Β --group=nginxΒ Β --with-http_ssl_moduleΒ Β --with-http_flv_moduleΒ Β --with-http_gzip_static_moduleΒ Β --http-log-path=/var/log/nginx/access.logΒ Β --http-client-body-temp-path=/var/tmp/nginx/client/Β Β --http-proxy-temp-path=/var/tmp/nginx/proxy/Β Β --http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ --with-http_stub_status_module --with-http_realip_module make make install
Now it’s time for the configuration files. See this for instructions
…
After right configuration the files it’s time to run the daemon who will be the firewall.
cp /usr/src/naxsi-0.44-1/contrib/rules_generator/http_config.py /etc/nginx/
run command :
/usr/bin/python /etc/nginx/http_config.py --cmd /usr/sbin/nginx -s reload -v 3
In my case there is an error with python library called argparse , so we need to install it :
apt-get install python-argparse
Run the daemon again and everything must be ok now π
PS. I wrote init script to daemonize the http_config.py because with & not work well.
Now we will see generated rulez by naxsi in http://mysite.com/RequestDenied
That’s it!