<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://lms.onnocenter.or.id/wiki/index.php?action=history&amp;feed=atom&amp;title=ModSecurity%3A_Instalasi_untuk_nginx</id>
	<title>ModSecurity: Instalasi untuk nginx - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://lms.onnocenter.or.id/wiki/index.php?action=history&amp;feed=atom&amp;title=ModSecurity%3A_Instalasi_untuk_nginx"/>
	<link rel="alternate" type="text/html" href="https://lms.onnocenter.or.id/wiki/index.php?title=ModSecurity:_Instalasi_untuk_nginx&amp;action=history"/>
	<updated>2026-04-20T19:54:34Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.45.1</generator>
	<entry>
		<id>https://lms.onnocenter.or.id/wiki/index.php?title=ModSecurity:_Instalasi_untuk_nginx&amp;diff=45553&amp;oldid=prev</id>
		<title>Onnowpurbo: New page: Sumber: https://www.howtoforge.com/tutorial/install-nginx-with-mod_security-on-ubuntu-15-04/     ModSecurity is an open-source Web Application Firewall (WAF) for Apache Nginx and IIS web s...</title>
		<link rel="alternate" type="text/html" href="https://lms.onnocenter.or.id/wiki/index.php?title=ModSecurity:_Instalasi_untuk_nginx&amp;diff=45553&amp;oldid=prev"/>
		<updated>2016-02-08T22:54:17Z</updated>

		<summary type="html">&lt;p&gt;New page: Sumber: https://www.howtoforge.com/tutorial/install-nginx-with-mod_security-on-ubuntu-15-04/     ModSecurity is an open-source Web Application Firewall (WAF) for Apache Nginx and IIS web s...&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;Sumber: https://www.howtoforge.com/tutorial/install-nginx-with-mod_security-on-ubuntu-15-04/&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
ModSecurity is an open-source Web Application Firewall (WAF) for Apache Nginx and IIS web server. This application layer firewall is developed by Trustwave&amp;#039;s SpiderLabs and released under Apache License 2.0. ModSecurity protects websites from hackers by using a set of regular expression rules to filter out commonly known exploits, it allows HTTP traffic monitoring, logging, real-time analysis, and attack detection. There are more than 16.000 rule available to detect attacks like SQL Injection, Cross-site Scripting (XSS), Local File Inclusion, Remote File Inclusion and application-specific rules for many web applications like Wordpress, Joomla, Drupal etc.&lt;br /&gt;
&lt;br /&gt;
In this tutorial, I will show you how to install mod_security for the fast Nginx web server. I will configure ModSecurity as a standalone module and then build Nginx from source to include ModSecurity.&lt;br /&gt;
Prerequisites&lt;br /&gt;
&lt;br /&gt;
    An Ubuntu 15.04 server, I will use the IP here 192.168.1.106.&lt;br /&gt;
    Root Privileges&lt;br /&gt;
&lt;br /&gt;
What we will do in this tutorial:&lt;br /&gt;
&lt;br /&gt;
    Update the Ubuntu 15.04 System and Repository.&lt;br /&gt;
    Install required Dependencies to build Nginx and ModSecurity.&lt;br /&gt;
    Download ModSecurity and Nginx.&lt;br /&gt;
    Install ModSecurity and Nginx.&lt;br /&gt;
    Configure Nginx.&lt;br /&gt;
    Configure ModSecurity.&lt;br /&gt;
    Configure OWASP Core Rule Set(CRS).&lt;br /&gt;
    Testing.&lt;br /&gt;
&lt;br /&gt;
All commands below have to be executed as root. Run:&lt;br /&gt;
&lt;br /&gt;
sudo -i&lt;br /&gt;
&lt;br /&gt;
to become root user on your server.&lt;br /&gt;
&lt;br /&gt;
1. Update System and Repository&lt;br /&gt;
&lt;br /&gt;
Before you start to install all dependencies, please update your system:&lt;br /&gt;
&lt;br /&gt;
apt-get update&lt;br /&gt;
apt-get upgrade&lt;br /&gt;
2. Install the build dependencies&lt;br /&gt;
&lt;br /&gt;
Install all packages that are required to compile Nginx and ModSecurity with apt command below:&lt;br /&gt;
&lt;br /&gt;
apt-get install git build-essential libpcre3 libpcre3-dev libssl-dev libtool autoconf apache2-prefork-dev libxml2-dev libcurl4-openssl-dev&lt;br /&gt;
3. Download ModSecurity and Nginx&lt;br /&gt;
&lt;br /&gt;
Go to directory &amp;quot;/usr/src/&amp;quot;, then clone the ModSecurity repository from  Github:&lt;br /&gt;
&lt;br /&gt;
cd /usr/src/&lt;br /&gt;
git clone https://github.com/SpiderLabs/ModSecurity.git modsecurity&lt;br /&gt;
&lt;br /&gt;
Download Nginx with the wget command, I will use the Nginx stable version 1.8 here. If you want to use another version, please go to Nginx download page to get a list of all available releases.&lt;br /&gt;
&lt;br /&gt;
wget http://nginx.org/download/nginx-1.8.0.tar.gz&lt;br /&gt;
4. Install ModSecurity and Nginx&lt;br /&gt;
&lt;br /&gt;
Now it&amp;#039;s time to install ModSecurity, please go to the /usr/src/modsecurity directory:&lt;br /&gt;
&lt;br /&gt;
cd /usr/src/modsecurity/&lt;br /&gt;
&lt;br /&gt;
And compile ModSecurity as standalone module on your server, so we can include it to the Nginx:&lt;br /&gt;
&lt;br /&gt;
./autogen.sh&lt;br /&gt;
./configure --enable-standalone-module --disable-mlogc&lt;br /&gt;
make&lt;br /&gt;
&lt;br /&gt;
Now go to the nginx directory, compile Nginx and include ModSecurity module:&lt;br /&gt;
&lt;br /&gt;
cd ../nginx-1.8.0&lt;br /&gt;
./configure \&lt;br /&gt;
  --user=www-data \&lt;br /&gt;
  --group=www-data \&lt;br /&gt;
  --with-debug \&lt;br /&gt;
  --with-ipv6 \&lt;br /&gt;
  --with-http_ssl_module \&lt;br /&gt;
  --add-module=/usr/src/modsecurity/nginx/modsecurity&lt;br /&gt;
&lt;br /&gt;
The configure command explained:&lt;br /&gt;
&lt;br /&gt;
Nginx will run under user and group &amp;quot;www-data&amp;quot;, and we activate the debug, ipv6 and ssl modules. And finally we include the ModSecurity module into Nginx.&lt;br /&gt;
&lt;br /&gt;
Now install Nginx:&lt;br /&gt;
&lt;br /&gt;
make&lt;br /&gt;
make install&lt;br /&gt;
&lt;br /&gt;
When the make install command is finished, you can see that Nginx is installed in the &amp;quot;/usr/local/nginx&amp;quot; directory:&lt;br /&gt;
&lt;br /&gt;
cd /usr/local/nginx/&lt;br /&gt;
&lt;br /&gt;
ll&lt;br /&gt;
drwxr-xr-x  2 root root 4096 Oct  3 07:21 conf/&lt;br /&gt;
drwxr-xr-x  2 root root 4096 Oct  3 07:21 html/&lt;br /&gt;
drwxr-xr-x  2 root root 4096 Oct  3 07:21 logs/&lt;br /&gt;
drwxr-xr-x  2 root root 4096 Oct  3 07:21 sbin/&lt;br /&gt;
5. Configure Nginx&lt;br /&gt;
&lt;br /&gt;
Edit the nginx configuration file with vi/vim and configure nginx to run under the user &amp;quot;www-data&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
cd /usr/local/nginx/&lt;br /&gt;
vi conf/nginx.conf&lt;br /&gt;
&lt;br /&gt;
On the first line, uncomment the &amp;quot;user&amp;quot; line and change the user to www-data:&lt;br /&gt;
&lt;br /&gt;
user  www-data;&lt;br /&gt;
&lt;br /&gt;
Save and Exit.&lt;br /&gt;
&lt;br /&gt;
Create a symlink for the nginx binary so we can use the command &amp;quot;nginx&amp;quot; by directly.&lt;br /&gt;
&lt;br /&gt;
ln -s /usr/local/nginx/sbin/nginx /bin/nginx&lt;br /&gt;
&lt;br /&gt;
Next we will create a systemd script for Nginx that is used to start / stop the Nginx daemon. Please go to the directory &amp;quot;/lib/systemd/system/&amp;quot; and create a new file &amp;quot;nginx.service&amp;quot; with vi:&lt;br /&gt;
&lt;br /&gt;
cd /lib/systemd/system/&lt;br /&gt;
vi nginx.service&lt;br /&gt;
&lt;br /&gt;
Paste the script below:&lt;br /&gt;
&lt;br /&gt;
[Service]&lt;br /&gt;
Type=forking&lt;br /&gt;
ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf&lt;br /&gt;
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf&lt;br /&gt;
ExecReload=/usr/local/nginx/sbin/nginx -s reload&lt;br /&gt;
KillStop=/usr/local/nginx/sbin/nginx -s stop&lt;br /&gt;
&lt;br /&gt;
KillMode=process&lt;br /&gt;
Restart=on-failure&lt;br /&gt;
RestartSec=42s&lt;br /&gt;
&lt;br /&gt;
PrivateTmp=true&lt;br /&gt;
LimitNOFILE=200000&lt;br /&gt;
&lt;br /&gt;
[Install]&lt;br /&gt;
WantedBy=multi-user.target&lt;br /&gt;
&lt;br /&gt;
Save and Exit.&lt;br /&gt;
&lt;br /&gt;
Now reload the systemd-daemon so that systemd loads our new Nginx service file.&lt;br /&gt;
&lt;br /&gt;
systemctl daemon-reload&lt;br /&gt;
&lt;br /&gt;
Test the nginx configuration and start nginx with systemctl command:&lt;br /&gt;
&lt;br /&gt;
nginx -t&lt;br /&gt;
systemctl start nginx&lt;br /&gt;
6. Configure ModSecurity&lt;br /&gt;
&lt;br /&gt;
Copy the ModSecurity configuration file to the nginx directory and name it &amp;quot;modsecurity.conf&amp;quot;:&lt;br /&gt;
&lt;br /&gt;
cp /usr/src/modsecurity/modsecurity.conf-recommended /usr/local/nginx/conf/modsecurity.conf&lt;br /&gt;
cp /usr/src/modsecurity/unicode.mapping /usr/local/nginx/conf/&lt;br /&gt;
&lt;br /&gt;
Open the modsecurity.conf file with the vi editor:&lt;br /&gt;
&lt;br /&gt;
cd /usr/Local/nginx/conf/&lt;br /&gt;
vi modsecurity.conf&lt;br /&gt;
&lt;br /&gt;
In line 7, change &amp;quot;DetectionOnly&amp;quot; to &amp;quot;on&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
SecRuleEngine On&lt;br /&gt;
&lt;br /&gt;
In line 38, increase the value of &amp;quot;SecRequestBodyLimit&amp;quot; to &amp;quot;100000000&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
SecRequestBodyLimit 100000000&lt;br /&gt;
&lt;br /&gt;
In line 192, change the value of &amp;quot;SecAuditLogType&amp;quot; to &amp;quot;Concurrent&amp;quot; and comment out the line  SecAuditLog and uncomment line 196.&lt;br /&gt;
&lt;br /&gt;
SecAuditLogType Concurrent&lt;br /&gt;
#SecAuditLog /var/log/modsec_audit.log&lt;br /&gt;
&lt;br /&gt;
# Specify the path for concurrent audit logging.&lt;br /&gt;
SecAuditLogStorageDir /opt/modsecurity/var/audit/&lt;br /&gt;
&lt;br /&gt;
Save and Exit.&lt;br /&gt;
&lt;br /&gt;
Now create new directory for the ModSecurity audit log and change the owner to www-data.&lt;br /&gt;
&lt;br /&gt;
mkdir -p /opt/modsecurity/var/audit/&lt;br /&gt;
chown -R www-data:www-data /opt/modsecurity/var/audit/&lt;br /&gt;
7. Configure OWASP Core Rule Set (CRS)&lt;br /&gt;
&lt;br /&gt;
Download the OWASP Core Rule Set from github.&lt;br /&gt;
&lt;br /&gt;
cd /usr/src/&lt;br /&gt;
git clone https://github.com/SpiderLabs/owasp-modsecurity-crs.git&lt;br /&gt;
&lt;br /&gt;
Go to directory &amp;quot;owasp-modsecurity-crs&amp;quot; and copy the directory &amp;quot;base_rules&amp;quot; to the nginx directory.&lt;br /&gt;
&lt;br /&gt;
cd owasp-modsecurity-crs&lt;br /&gt;
cp -R base_rules/ /usr/Local/nginx/conf/&lt;br /&gt;
&lt;br /&gt;
Edit modsecurity.conf and add OWASP CRS.&lt;br /&gt;
&lt;br /&gt;
cd /usr/Local/nginx/conf/&lt;br /&gt;
vi modsecurity.conf&lt;br /&gt;
&lt;br /&gt;
Please go to the end of the file and add the following configuration:&lt;br /&gt;
&lt;br /&gt;
#DefaultAction&lt;br /&gt;
SecDefaultAction &amp;quot;log,deny,phase:1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
#If you want to load single rule /usr/loca/nginx/conf&lt;br /&gt;
#Include base_rules/modsecurity_crs_41_sql_injection_attacks.conf&lt;br /&gt;
&lt;br /&gt;
#Load all Rule&lt;br /&gt;
Include base_rules/*.conf&lt;br /&gt;
&lt;br /&gt;
#Disable rule by ID from error message (for my wordpress)&lt;br /&gt;
SecRuleRemoveById 981172 981173 960032 960034 960017 960010 950117 981004 960015&lt;br /&gt;
&lt;br /&gt;
Save and Exit.&lt;br /&gt;
&lt;br /&gt;
As the last step, add the modsecurity.conf file to the Nginx configuration by editing the &amp;quot;nginx.conf&amp;quot; file.&lt;br /&gt;
&lt;br /&gt;
vi conf/nginx.conf&lt;br /&gt;
&lt;br /&gt;
Add the modsecurity.conf:&lt;br /&gt;
&lt;br /&gt;
[.....]&lt;br /&gt;
&lt;br /&gt;
#Enable ModSecurity&lt;br /&gt;
ModSecurityEnabled on;&lt;br /&gt;
ModSecurityConfig modsecurity.conf;&lt;br /&gt;
&lt;br /&gt;
root html;&lt;br /&gt;
index index.php index.html index.htm;&lt;br /&gt;
&lt;br /&gt;
[.....]&lt;br /&gt;
&lt;br /&gt;
Save and exit.&lt;br /&gt;
&lt;br /&gt;
Restart Nginx to apply the configuration changes:&lt;br /&gt;
&lt;br /&gt;
systemctl restart nginx&lt;br /&gt;
8. Testing&lt;br /&gt;
&lt;br /&gt;
I have a WordPress site running on Nginx and ModSecurity, it is working fine. For testing I will install a new plugin that is vulnerable for XSS and SQL Injection.&lt;br /&gt;
&lt;br /&gt;
Here are the results:&lt;br /&gt;
&lt;br /&gt;
XSS forbidden&lt;br /&gt;
https://www.exploit-db.com/exploits/37107/ &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Referensi==&lt;br /&gt;
&lt;br /&gt;
* https://www.howtoforge.com/tutorial/install-nginx-with-mod_security-on-ubuntu-15-04/&lt;/div&gt;</summary>
		<author><name>Onnowpurbo</name></author>
	</entry>
</feed>