From abca32ba8e6675bb4b8327e60f7cdfd30312065f Mon Sep 17 00:00:00 2001 From: weltschraet Date: Thu, 16 May 2019 09:09:34 +0200 Subject: [PATCH] reduce memory footprint and cpu usage when modsecurity and owasp rules are enabled globally --- rootfs/etc/nginx/template/nginx.tmpl | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/rootfs/etc/nginx/template/nginx.tmpl b/rootfs/etc/nginx/template/nginx.tmpl index 384550264..ebdfcde5d 100755 --- a/rootfs/etc/nginx/template/nginx.tmpl +++ b/rootfs/etc/nginx/template/nginx.tmpl @@ -137,6 +137,17 @@ http { {{ end }} {{ end }} + {{ if $all.Cfg.EnableModsecurity }} + modsecurity on; + + modsecurity_rules_file /etc/nginx/modsecurity/modsecurity.conf; + + {{ if $all.Cfg.EnableOWASPCoreRules }} + modsecurity_rules_file /etc/nginx/owasp-modsecurity-crs/nginx-modsecurity.conf; + {{ end }} + + {{ end }} + {{ if $cfg.UseGeoIP }} {{/* databases used to determine the country depending on the client IP address */}} {{/* http://nginx.org/en/docs/http/ngx_http_geoip_module.html */}} @@ -1102,15 +1113,17 @@ stream { set $proxy_host $proxy_upstream_name; {{ if (or $location.ModSecurity.Enable $all.Cfg.EnableModsecurity) }} + {{ if not $all.Cfg.EnableModsecurity }} modsecurity on; modsecurity_rules_file /etc/nginx/modsecurity/modsecurity.conf; + {{ end }} {{ if $location.ModSecurity.Snippet }} modsecurity_rules ' {{ $location.ModSecurity.Snippet }} '; - {{ else if (or $location.ModSecurity.OWASPRules $all.Cfg.EnableOWASPCoreRules) }} + {{ else if (and ((not $all.Cfg.EnableOWASPCoreRules) $location.ModSecurity.OWASPRules))}} modsecurity_rules_file /etc/nginx/owasp-modsecurity-crs/nginx-modsecurity.conf; {{ end }}