How To Set Up ModSecurity With Apache On Debian/Ubuntu
How To Set Up ModSecurity With Apache On Debian/Ubuntu
Menu
Menu
The Apache web server is highly customizable and can be configured in multiple ways
to suit your needs. There are many third-party modules that you can use to configure
Apache to your preference.
https://www.tecmint.com/install-modsecurity-with-apache-on-debian-ubuntu/ 1/23
14/11/22, 7:58 How to Set Up ModSecurity with Apache on Debian/Ubuntu
Linux Foundation LFCS and LFCE Certification Preparation Guide - Get This Book
[ You might also like: 5 Tools to Scan a Linux Server for Malware and Rootkits ]
The ModSecurity application firewall forms an integral part of PCI DSS compliance in
shielding sites from external attacks. When the module is enabled it triggers a ‘403
Forbidden Error’ which simply implies that you have insufficient permissions to access
the resource on the webserver.
In this guide, we will show you how to set up and configure ModSecurity to work with
Apache on Debian and Ubuntu Linux.
Next, install the ModSecurity package alongside other dependencies and libraries.
https://www.tecmint.com/install-modsecurity-with-apache-on-debian-ubuntu/ 2/23
14/11/22, 7:58 How to Set Up ModSecurity with Apache on Debian/Ubuntu
https://www.tecmint.com/install-modsecurity-with-apache-on-debian-ubuntu/ 3/23
14/11/22, 7:58 How to Set Up ModSecurity with Apache on Debian/Ubuntu
SecRuleEngine DetectionOnly
Set it to:
SecRuleEngine On
https://www.tecmint.com/install-modsecurity-with-apache-on-debian-ubuntu/ 4/23
14/11/22, 7:58 How to Set Up ModSecurity with Apache on Debian/Ubuntu
$ cd coreruleset/
https://www.tecmint.com/install-modsecurity-with-apache-on-debian-ubuntu/ 5/23
14/11/22, 7:58 How to Set Up ModSecurity with Apache on Debian/Ubuntu
IncludeOptional /etc/modsecurity/*.conf
Include /etc/modsecurity/rules/*.conf
https://www.tecmint.com/install-modsecurity-with-apache-on-debian-ubuntu/ 6/23
14/11/22, 7:58 How to Set Up ModSecurity with Apache on Debian/Ubuntu
https://www.tecmint.com/install-modsecurity-with-apache-on-debian-ubuntu/ 7/23
14/11/22, 7:58 How to Set Up ModSecurity with Apache on Debian/Ubuntu
Next, we will create a blocking rule that will block access to a certain URL when
accessed by a web browser.
Append these lines at the end before the ‘Virtualhost’ closing tag.
SecRuleEngine On
Feel free to set the ‘id’ and ‘msg’ tags to whatever desirable values.
Then restart the Apache webserver to apply the changes made to the virtual host
configuration file.
https://www.tecmint.com/install-modsecurity-with-apache-on-debian-ubuntu/ 8/23
14/11/22, 7:58 How to Set Up ModSecurity with Apache on Debian/Ubuntu
On your web browser, try to visit the URL shown with ?testparam=test at the end.
http://server-ip/?testparam=test
You get a ‘403 Forbidden error’ indicating that you have been blocked from accessing
the resource.
You can further confirm the client was blocked by checking the error logs as follows.
https://www.tecmint.com/install-modsecurity-with-apache-on-debian-ubuntu/ 9/23
14/11/22, 7:58 How to Set Up ModSecurity with Apache on Debian/Ubuntu
[ You might also like: How to Install ModSecurity for Nginx on Debian/Ubuntu ]
This is confirmation that we have successfully set up ModSecurity to detect and block
unwanted traffic. In this guide, we have walked you through the process of setting up
ModSecurity with Apache on Debian/Ubuntu systems.
If you liked this article, then do subscribe to email alerts for Linux tutorials. If you
have any questions or doubts? do ask for help in the comments section.
https://www.tecmint.com/install-modsecurity-with-apache-on-debian-ubuntu/ 10/23
14/11/22, 7:58 How to Set Up ModSecurity with Apache on Debian/Ubuntu
TecMint is the fastest growing and most trusted community site for
any kind of Linux Articles, Guides and Books on the web. Millions of
people visit TecMint! to search or browse the thousands of
published articles available FREELY to all.
If you like what you are reading, please consider buying us a coffee
( or 2 ) as a token of appreciation.
Related Posts
https://www.tecmint.com/install-modsecurity-with-apache-on-debian-ubuntu/ 11/23
14/11/22, 7:58 How to Set Up ModSecurity with Apache on Debian/Ubuntu
https://www.tecmint.com/install-modsecurity-with-apache-on-debian-ubuntu/ 12/23
14/11/22, 7:58 How to Set Up ModSecurity with Apache on Debian/Ubuntu
https://www.tecmint.com/install-modsecurity-with-apache-on-debian-ubuntu/ 13/23