Setup ModSecurity 3 and Nginx in Debian 8

Short Howto to setup the current version of ModSecurity v3 (2016-11-14) with Nginx on Debian 8

 

Debian stand installation – SSH & System utilities

apt-get install aptitude postfix bison flex make automake gcc pkg-config openssl libssl-dev libtool doxygen git curl zlib1g-dev libxml2-dev libpcre3-dev libcurl4-openssl-dev build-essential unzip libyajl-dev yajl-tools liblmdb-dev rdmacm-utils libgeoip-dev multitail

cd /opt/
git clone https://github.com/SpiderLabs/ModSecurity
cd ModSecurity
git checkout v3/master
git submodule init
git submodule update
sh build.sh
./configure
make
make install
cd /opt/
git clone https://github.com/SpiderLabs/ModSecurity-nginx
cd /opt/ModSecurity-nginx
git checkout experimental
cd /opt/
wget http://nginx.org/download/nginx-1.11.5.tar.gz
tar -xvzf nginx-1.11.5.tar.gz
cd /opt/nginx-1.11.5
./configure –prefix=/opt/nginx/ –add-dynamic-module=/opt/ModSecurity-nginx
make
make install
cd /opt/nginx/
mkdir modsec
cd modsec
git clone https://github.com/SpiderLabs/owasp-modsecurity-crs.git
cd owasp-modsecurity-crs/
mv crs-setup.conf.example crs-setup.conf
vi ../main.conf ->
Include „/opt/nginx/modsec/modsecurity.conf“
Include „/opt/nginx/modsec/owasp-modsecurity-crs/crs-setup.conf“
Include „/opt/nginx/modsec/owasp-modsecurity-crs/rules/*.conf“
cp /opt/ModSecurity/modsecurity.conf-recommended /opt/nginx/modsec/modsecurity.conf
vi /opt/nginx/conf/nginx.conf ->
load_module „modules/ngx_http_modsecurity_module.so“;
In server: ->
modsecurity on;
modsecurity_rules_file /opt/nginx/modsec/main.conf;