How to Set Up ModSecurity Web Application Firewall with NGINX Server?

How to Set Up ModSecurity Web Application Firewall with NGINX Server?

An open-source web application firewall (WAF) that runs on several platforms is called ModSecurity. It aids in identifying and thwarting web application attacks. This module can strengthen server security by thwarting popular exploits like code injection. It contains guidelines for guarding against trojans, malicious user agents, SQL injection, cross-site scripting, and other attacks.

Discover the basic security for applications with the NGINX load balancer

ModSecurity is pre-installed on AccuWeb.Cloud certified NGINX stacks, which comprise load balancers and application servers. Take these actions to activate this feature on your containers:

Step 1. To load the shared NGINX module for ModSecurity, uncomment the corresponding line in the /etc/nginx/nginx.conf file.


#load_module modules/ngx_http_modsecurity_module.so;

Uncomment the Corresponding file

Save the changes made to the file.

Step 2. Then, in the configuration file found at /etc/nginx/nginx.conf for the NGINX application server stack (or, in our case, /etc/nginx/nginx-jelastic.conf for the load balancer), you can activate ModSecurity by deleting the ‘#’ symbol from the designated lines.


#modsecurity on;
#modsecurity_rules_file /etc/nginx/conf.d/modsecurity/modsec_includes.conf;

Activate ModSecurity

Remember to save the file after making your adjustments.

Step 3. According to the configuration file at /etc/nginx/conf.d/modsecurity/modsec_includes.conf, a default OWASP ModSecurity Core Rule Set (CRS) is included. This set offers general protection against common vulnerabilities typically found in web applications.

Core Rule Set is included

Save $100 in the next
5:00 minutes?

Register Here

Step 4. After making these changes, remember to restart the relevant NGINX node to apply all the customizations.

Restart NGINX Node

Step 5. Now that ModSecurity is protecting your application, you can confirm that it’s active by running the command `nginx -V` on the node (for example, through Web SSH) and checking for the ModSecurity module in the output list.

Running Status

Step 6. You can test ModSecurity by simulating an attack on your application. For instance, try adding the `/?q=”><script>alert(1)</script>` string to your domain environment. If ModSecurity is functioning correctly, you should see a 403 error page, and the action will be logged in the error log file.

Test ModSecurity

ModSecurity is up and running, protecting your online application.

Know more about how to use load balancing for highly available applications.

Start a free trial now to use AccuWeb.Cloud platform for high-level protection while managing your projects.

Save $100 in the next
5:00 minutes?

Register Here