90 likes | 111 Views
Modsecurity protects websites from malicious attacks and security threats. Here's how to install and configure modsecurity in NGINX. #nginx #modsecurity #webdevelopment <br><br>Visit https://ubiq.co/tech-blog/how-to-install-configure-modsecurity-in-nginx/
E N D
Install Prerequisites Open terminal and run the following command to install prerequisites for modsecurity CentOS/Redhat #yum groupinstall -y "Development Tools" #yum install -y httpd httpd-devel pcre pcre-devel libxml2 libxml2-devel curl curl-devel openssl openssl-devel Debian/Ubuntu $ sudo apt-get install -y git build-essential libpcre3 libpcre3-dev libssl-dev libtool autoconf apache2-dev libxml2-dev libcurl4-openssl-dev automake pkgconf
Download NGINX and Modsecurity Download NGINX and modsecurity with following commands. Update the NGINX version as per your requirement $ wget http://nginx.org/download/nginx-1.9.15.tar.gz $ gunzip -c nginx-1.9.15.tar.gz | tar xvf – You will see a new folder nginx-1.9.15 created. $ wget https://www.modsecurity.org/tarball/2.9.1/modsecurity-2.9.1.tar.gz $ gunzip -c modsecurity-2.9.1.tar.gz | tar xvf – You will see a new folder modsecurity-2.9.1 created.
Install NGINX with Modsecurity Run the following commands to compile modsecurity $ cd modsecurity-2.9.1 $ ./configure --enable-standalone-module $ make Run the following commands to compile and install NGINX with modsecurity. $ cd nginx-1.9.15 $ ./configure --add-module=../modsecurity-2.9.1/nginx/modsecurity $ make $ make install
Configure modsecurity (1 of 2) First, we need to copy 2 modsecurity configuration files modsecurity.conf-recommended and unicode.mapping to the same folder as our nginx.conf file (e.g /usr/local/nginx/conf). You will find these 2 files in modsecurity folder that was created in step 2. Run the following commands to copy the 2 configuration files. Replace the folder path below as per your requirement. For our example, let us say our folder was created in /home/ $ cp /home/modsecurity-2.9.1/modsecurity.conf-recommended /usr/local/nginx/conf/ $ cp /home/modsecurity-2.9.1/unicode.mapping /usr/local/nginx/conf/ We will also rename modsecurity.conf-recommended to modsecurity.conf $ mv /usr/local/nginx/conf/modsecurity.conf-recommended /usr/local/nginx/conf/modsecurity.conf
Configure modsecurity (2 of 2) Open nginx.conf file and add the following lines to location / block ModSecurityEnabled on; ModSecurityConfig modsecurity.conf; So your location block will look like location / { ... ModSecurityEnabled on; ModSecurityConfig modsecurity.conf; }
Restart NGINX Server Run the following command to check syntax of your updated config file. $ sudo nginx -t If there are no errors, run the following command to restart NGINX server. $ sudo service nginx reload #debian/ubuntu $ systemctl restart nginx #redhat/centos
Verify Modsecurity Installation Run the following command to verify modsecurity installation. $ nginx -v If modsecurity is successfully installed and enabled, you will see modsecurity mentioned in the output. nginx version: nginx/1.9.15 built by gcc 4.4.7 20120313 (Red Hat 4.4.7-16) (GCC) configure arguments: --add-module=../modsecurity-2.9.1/nginx/modsecurity
Thank You Visit for details https://ubiq.co/tech-blog/how-to-install-configure-modsecurity-in-nginx/