Listen to this Post
Milad Zangeneh, a Senior DevOps Engineer, shares his experience with automating the installation and configuration of Nginx with ModSecurity using Git pipelines. This automation simplifies the process of securing web servers by providing pre-compiled .deb binaries for Ubuntu 20 to 24 and Debian 12. The article provides a step-by-step guide on how to add the repository and install Nginx with ModSecurity using a single apt command.
Step-by-Step Installation Guide:
1. Add the Repository:
echo "deb [arch=amd64] http://example.com/nginx-modsecurity $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/nginx-modsecurity.list
2. Import the GPG Key:
wget -qO - http://example.com/nginx-modsecurity/KEY.gpg | sudo apt-key add -
3. Update the Package List:
sudo apt update
4. Install Nginx with ModSecurity:
sudo apt install nginx-modsecurity
5. Enable ModSecurity in Nginx:
sudo ln -s /usr/share/modsecurity-crs/nginx-modsecurity.conf /etc/nginx/modsecurity.conf sudo systemctl restart nginx
Dockerfile for Test Environment:
For those interested in a Docker setup, here’s a sample Dockerfile for a test environment:
FROM ubuntu:20.04 RUN apt update && apt install -y wget gnupg2 RUN echo "deb [arch=amd64] http://example.com/nginx-modsecurity focal main" | tee /etc/apt/sources.list.d/nginx-modsecurity.list RUN wget -qO - http://example.com/nginx-modsecurity/KEY.gpg | apt-key add - RUN apt update && apt install -y nginx-modsecurity COPY nginx.conf /etc/nginx/nginx.conf EXPOSE 80 CMD ["nginx", "-g", "daemon off;"]
What Undercode Say:
In conclusion, automating the installation and configuration of Nginx with ModSecurity significantly enhances web server security by reducing manual errors and ensuring consistent updates. The provided commands and Dockerfile offer a practical approach to implementing this solution. For further reading on ModSecurity rules and configurations, visit the ModSecurity GitHub repository. Additionally, exploring Nginx documentation can provide deeper insights into optimizing your web server setup. Remember, security is an ongoing process, and leveraging automation tools like Git pipelines and Docker can streamline this process, making your infrastructure more resilient against various types of cyber attacks. Always ensure to keep your systems updated and regularly review your security configurations to adapt to new threats.
References:
initially reported by: https://www.linkedin.com/posts/milad-zanganeh_nginx-modsecurity-waf-activity-7301688071685627904-IAi_ – Hackers Feeds
Extra Hub:
Undercode AI


