1 / 9

How to Install ModSecurity in NGINX

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/

Download Presentation

How to Install ModSecurity in NGINX

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. How To Install & Configure Modsecurity in Nginx

  2. 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

  3. 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.

  4. 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

  5. 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

  6. 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; }

  7. 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

  8. 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

  9. Thank You Visit for details https://ubiq.co/tech-blog/how-to-install-configure-modsecurity-in-nginx/

More Related