Skip to content

Linux VPS & VPS Windows Setup Guide | NetCloud24 ModSecurity 3 with Nginx on Ubuntu 22.04

Netcloud24
Cloud Infrastructure Expert
HOSTING H1

Free web hosting H1

5 GB of storage and SSL for a small website or WordPress project.

Explore hosting H1
WINDOWS VPS + RDS

Run Windows applications remotely

Windows Server 2022 or 2025 and RDS CALs included in the plan. Choose resources and user capacity for your business.

Explore Windows VPS
NetCloud24 Expert Guides Open the dedicated video page

Video transcript: NetCloud24 Expert Guides. Practical knowledge for a reliable cloud. Cloud and VPS expertise, security, performance, and step-by-step tutorials. Learn, deploy, and keep building with NetCloud24.

 

 

Introduction

ModSecurity is an open-source web application firewall (WAF) that helps protect web applications from various attacks. In this guide, you will learn how to install ModSecurity 3 with Nginx on Ubuntu 22.04, which can be efficiently hosted on a .

Prerequisites

  • An Ubuntu 22.04 server with root access
  • Basic knowledge of Linux commands
  • An active internet connection
  • Nginx installed on your server

Step 1: Update Your System

Start by updating your package index and upgrading existing packages:

sudo apt update && sudo apt upgrade -y

Step 2: Install Required Dependencies

Install the necessary packages:

sudo apt install build-essential git curl libtool libpcre3 libpcre3-dev zlib1g zlib1g-dev libssl-dev -y

Step 3: Install Nginx

If you haven’t already installed Nginx, you can do so with the following command:

sudo apt install nginx -y

Start and enable Nginx to run at boot:

Visual overview of Linux VPS & VPS Windows Setup Guide | NetCloud24 ModSecurity 3 with Nginx on Ubuntu 22.04
Visual overview: Linux VPS & VPS Windows Setup Guide | NetCloud24 ModSecurity 3 with Nginx on Ubuntu 22.04
sudo systemctl start nginx
sudo systemctl enable nginx

Step 4: Clone the ModSecurity Repository

Clone the ModSecurity 3 GitHub repository:

git clone --depth 1 https://github.com/SpiderLabs/ModSecurity.git

Change into the ModSecurity directory:

cd ModSecurity

Step 5: Compile and Install ModSecurity

Run the following commands to compile and install ModSecurity:

git submodule init
git submodule update
./build.sh
./configure
make
sudo make install

Step 6: Install ModSecurity Nginx Connector

Clone the ModSecurity Nginx connector repository:

git clone --depth 1 https://github.com/SpiderLabs/modsecurity-nginx.git

Change into the connector directory:

cd modsecurity-nginx

Now, you need to compile Nginx with ModSecurity:

sudo apt install nginx-extras -y
sudo apt install libnginx-mod-http-modsecurity -y

Step 7: Configure Nginx to Use ModSecurity

Edit your Nginx configuration file to include ModSecurity:

sudo nano /etc/nginx/nginx.conf

Add the following line inside the http block:

Key topics covered in Linux VPS & VPS Windows Setup Guide | NetCloud24 ModSecurity 3 with Nginx on Ubuntu 22.04
Key topics covered in this NetCloud24 guide.
modsecurity on;

And specify the ModSecurity configuration file:

modsecurity_rules_file /etc/nginx/modsec/main.conf;

Step 8: Create the Main Configuration File

Create the ModSecurity configuration file:

sudo mkdir /etc/nginx/modsec
sudo nano /etc/nginx/modsec/main.conf

Add your ModSecurity rules. You can start with the default rules:

Include /usr/local/nginx/conf/modsecurity.conf

Step 9: Restart Nginx

After making changes to the configuration, restart Nginx:

sudo systemctl restart nginx

Step 10: Verify ModSecurity Installation

To verify that ModSecurity is working, check the Nginx error log for any entries related to ModSecurity:

sudo tail -f /var/log/nginx/error.log

Step 11: Conclusion

You have successfully installed ModSecurity 3 with Nginx on Ubuntu 22.04. This setup provides enhanced security for your web applications, particularly beneficial when hosted on a . For further assistance, explore various solutions, including Windows VPSVirtual Private Server Hosting and Windows VPS Hosting UK for optimal performance and security.

© 2024 ModSecurity Installation Tutorial. All rights reserved.

Practical checklist for Linux VPS & VPS Windows Setup Guide | NetCloud24 ModSecurity 3 with Nginx on Ubuntu 22.04
Practical checklist for applying the guidance in this article.
Linux VPS & VPS Windows Setup Guide | NetCloud24 ModSecurity 3 with Nginx on Ubuntu 22.04
Linux VPS & VPS Windows Setup Guide | NetCloud24 ModSecurity 3 with Nginx on Ubuntu 22.04
Explore more

More on this topic

Netcloud24
Netcloud24
Cloud Infrastructure Expert · NetCloud24

Comments are closed.

Linux VPS & VPS Windows Setup Guide | NetCloud24 ModSecurity 3 with Nginx on Ubuntu 22.04

Netcloud24
Cloud Infrastructure Expert
HOSTING H1

Free web hosting H1

5 GB of storage and SSL for a small website or WordPress project.

Explore hosting H1
WINDOWS VPS + RDS

Run Windows applications remotely

Windows Server 2022 or 2025 and RDS CALs included in the plan. Choose resources and user capacity for your business.

Explore Windows VPS
NetCloud24 Expert Guides Open the dedicated video page

Video transcript: NetCloud24 Expert Guides. Practical knowledge for a reliable cloud. Cloud and VPS expertise, security, performance, and step-by-step tutorials. Learn, deploy, and keep building with NetCloud24.

 

 

Introduction

ModSecurity is an open-source web application firewall (WAF) that helps protect web applications from various attacks. In this guide, you will learn how to install ModSecurity 3 with Nginx on Ubuntu 22.04, which can be efficiently hosted on a .

Prerequisites

  • An Ubuntu 22.04 server with root access
  • Basic knowledge of Linux commands
  • An active internet connection
  • Nginx installed on your server

Step 1: Update Your System

Start by updating your package index and upgrading existing packages:

sudo apt update && sudo apt upgrade -y

Step 2: Install Required Dependencies

Install the necessary packages:

sudo apt install build-essential git curl libtool libpcre3 libpcre3-dev zlib1g zlib1g-dev libssl-dev -y

Step 3: Install Nginx

If you haven’t already installed Nginx, you can do so with the following command:

sudo apt install nginx -y

Start and enable Nginx to run at boot:

Visual overview of Linux VPS & VPS Windows Setup Guide | NetCloud24 ModSecurity 3 with Nginx on Ubuntu 22.04
Visual overview: Linux VPS & VPS Windows Setup Guide | NetCloud24 ModSecurity 3 with Nginx on Ubuntu 22.04
sudo systemctl start nginx
sudo systemctl enable nginx

Step 4: Clone the ModSecurity Repository

Clone the ModSecurity 3 GitHub repository:

git clone --depth 1 https://github.com/SpiderLabs/ModSecurity.git

Change into the ModSecurity directory:

cd ModSecurity

Step 5: Compile and Install ModSecurity

Run the following commands to compile and install ModSecurity:

git submodule init
git submodule update
./build.sh
./configure
make
sudo make install

Step 6: Install ModSecurity Nginx Connector

Clone the ModSecurity Nginx connector repository:

git clone --depth 1 https://github.com/SpiderLabs/modsecurity-nginx.git

Change into the connector directory:

cd modsecurity-nginx

Now, you need to compile Nginx with ModSecurity:

sudo apt install nginx-extras -y
sudo apt install libnginx-mod-http-modsecurity -y

Step 7: Configure Nginx to Use ModSecurity

Edit your Nginx configuration file to include ModSecurity:

sudo nano /etc/nginx/nginx.conf

Add the following line inside the http block:

Key topics covered in Linux VPS & VPS Windows Setup Guide | NetCloud24 ModSecurity 3 with Nginx on Ubuntu 22.04
Key topics covered in this NetCloud24 guide.
modsecurity on;

And specify the ModSecurity configuration file:

modsecurity_rules_file /etc/nginx/modsec/main.conf;

Step 8: Create the Main Configuration File

Create the ModSecurity configuration file:

sudo mkdir /etc/nginx/modsec
sudo nano /etc/nginx/modsec/main.conf

Add your ModSecurity rules. You can start with the default rules:

Include /usr/local/nginx/conf/modsecurity.conf

Step 9: Restart Nginx

After making changes to the configuration, restart Nginx:

sudo systemctl restart nginx

Step 10: Verify ModSecurity Installation

To verify that ModSecurity is working, check the Nginx error log for any entries related to ModSecurity:

sudo tail -f /var/log/nginx/error.log

Step 11: Conclusion

You have successfully installed ModSecurity 3 with Nginx on Ubuntu 22.04. This setup provides enhanced security for your web applications, particularly beneficial when hosted on a . For further assistance, explore various solutions, including Windows VPSVirtual Private Server Hosting and Windows VPS Hosting UK for optimal performance and security.

© 2024 ModSecurity Installation Tutorial. All rights reserved.

Practical checklist for Linux VPS & VPS Windows Setup Guide | NetCloud24 ModSecurity 3 with Nginx on Ubuntu 22.04
Practical checklist for applying the guidance in this article.
Linux VPS & VPS Windows Setup Guide | NetCloud24 ModSecurity 3 with Nginx on Ubuntu 22.04
Linux VPS & VPS Windows Setup Guide | NetCloud24 ModSecurity 3 with Nginx on Ubuntu 22.04
Explore more

More on this topic

Netcloud24
Netcloud24
Cloud Infrastructure Expert · NetCloud24

Comments are closed.