Would you like to learn how to install the Nginx Modsecurity feature? In this tutorial, we are going to configure the Nginx Modsecurity feature on a computer running Ubuntu Linux.
• Ubuntu 18
• Ubuntu 19
• Ubuntu 20
• Nginx 1.18.0
• ModSecurity 3.0.4
Equipment list
The following section presents the list of equipment used to create this tutorial.
As an Amazon Associate, I earn from qualifying purchases.
Nginx – Related Tutorial:
On this page, we offer quick access to a list of tutorials related to Nginx.
Tutorial Nginx – ModSecurity installation
Install the Nginx server.
Install the required packages.
Install the software named SSDEP.
Download the latest version of ModSecurity.
Compile and install ModSecurity.
Download the latest version of the Nginx connector for ModSecurity.
Verify the version of Nginx installed on your system.
Here is the command output.
Download the source code of the same version of Nginx installed on your system.
Compile and install the Nginx connector.
Download and install the ModSecurity Core Rule Set.
Congratulations! You have finished the ModSecurity installation on the Nginx server.
Tutorial Nginx – ModSecurity configuration
Edit the Nginx configuration file.
Add the following line in the Nginx configuration file.
Here is the file before our configuration.
Here is the file after our configuration.
Create a directory named Modsec and copy the required configuration files.
Edit the ModSecurity configuration file.
Locate the following lines.
Change these lines to the following configuration.
Here is the file after our configuration.
Create a file to enable ModSecurity to use the installed CRS rules.
Here is the file content.
Edit the Nginx configuration file for the default website.
Add the following line in the Nginx configuration file.
Here is the file before our configuration.
Here is the file after our configuration.
Restart the Nginx service.
Optionally, use your browser to send a test request to the Nginx server.
After sending a test request, verify the ModSecurity log
Congratulations! You have finished the ModSecurity configuration on the Nginx server.