Skip to content

Commit 7f6ddcd

Browse files
author
julian
committed
add owasp-modsecurity-crs rules
1 parent a2d9753 commit 7f6ddcd

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

Dockerfile

+13-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
FROM alpine:3.8
22
MAINTAINER JulianWang <[email protected]>
33

4-
ENV NGINX_VERSION 1.15.3
4+
ENV NGINX_VERSION 1.15.8
55

66
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
77
RUN GPG_KEYS=B0F4253373F8F6F510D42178520A9993A1C052F8 \
@@ -103,9 +103,8 @@ RUN GPG_KEYS=B0F4253373F8F6F510D42178520A9993A1C052F8 \
103103
&& tar -zxC /usr/src -f nginx.tar.gz \
104104
&& rm nginx.tar.gz \
105105
&& cd /usr/src \
106-
&& git clone https://github.com/SpiderLabs/ModSecurity \
106+
&& git clone --depth 1 -b v3/master --single-branch https://github.com/SpiderLabs/ModSecurity \
107107
&& cd ModSecurity \
108-
&& git checkout v3/master \
109108
&& git submodule init \
110109
&& git submodule update \
111110
&& sed -i -e 's/u_int64_t/uint64_t/g' \
@@ -126,8 +125,18 @@ RUN GPG_KEYS=B0F4253373F8F6F510D42178520A9993A1C052F8 \
126125
&& ./configure \
127126
&& make \
128127
&& make install \
128+
&& mkdir -p /etc/nginx/modsec.d \
129+
&& cp /usr/src/ModSecurity/modsecurity.conf-recommended /etc/nginx/modsec.d \
130+
&& mv /etc/nginx/modsec.d/modsecurity.conf-recommended /etc/nginx/modsec.d/modsecurity.conf \
131+
&& cp /usr/src/ModSecurity/unicode.mapping /etc/nginx/modsec.d \
132+
&& sed -i -e 's/SecRuleEngine DetectionOnly/SecRuleEngine On/g' /etc/nginx/modsec.d/modsecurity.conf \
133+
&& cd /etc/nginx/modsec.d \
134+
&& git clone --depth 1 https://github.com/SpiderLabs/owasp-modsecurity-crs \
135+
&& cd owasp-modsecurity-crs \
136+
&& mv crs-setup.conf.example crs-setup.conf \
137+
&& printf "include /etc/nginx/modsec.d/modsecurity.conf\ninclude /etc/nginx/modsec.d/owasp-modsecurity-crs/crs-setup.conf\ninclude /etc/nginx/modsec.d/owasp-modsecurity-crs/rules/*.conf\n" > /etc/nginx/modsec.d/main.conf \
129138
&& cd /usr/src \
130-
&& git clone https://github.com/SpiderLabs/ModSecurity-nginx \
139+
&& git clone --depth 1 https://github.com/SpiderLabs/ModSecurity-nginx.git \
131140
&& cd /usr/src/nginx-$NGINX_VERSION \
132141
&& ./configure $CONFIG --with-debug \
133142
&& make -j$(getconf _NPROCESSORS_ONLN) \

nginx.conf

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ http {
2020
'"$http_user_agent" "$http_x_forwarded_for"';
2121

2222
access_log /var/log/nginx/access.log main;
23+
modsecurity on;
24+
modsecurity_rules_file /etc/nginx/modsec.d/main.conf;
2325

2426
sendfile on;
2527
#tcp_nopush on;

nginx.vh.default.conf

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ server {
55
#charset koi8-r;
66
#access_log /var/log/nginx/host.access.log main;
77

8-
modsecurity on;
98
location / {
109
root /usr/share/nginx/html;
1110
index index.html index.htm;

0 commit comments

Comments
 (0)