@@ -9,21 +9,87 @@ WORKDIR $WORKING_DIRECTORY
99
1010# ENV build variables
1111ENV LANG C.UTF-8
12- ENV NPS_VERSION=1.9.32.2
1312ENV NGINX_VERSION=1.11.1
1413ENV MODSEC_VERSION=2.9.1
15- ENV NGINX_ADD_MODULES=" --add-module=$WORKING_DIRECTORY/ModSecurity/nginx/modsecurity "
16- ENV NGINX_EXTRA_MODULES=" --with-http_realip_module --with-http_ssl_module "
14+ ENV NGINX_BASE_CONFIG="\
15+ --prefix=/etc/nginx \
16+ --sbin-path=/usr/sbin/nginx \
17+ --modules-path=/usr/lib/nginx/modules \
18+ --conf-path=/etc/nginx/nginx.conf \
19+ --error-log-path=/var/log/nginx/error.log \
20+ --http-log-path=/var/log/nginx/access.log \
21+ --pid-path=/var/run/nginx.pid \
22+ --lock-path=/var/run/nginx.lock \
23+ --http-client-body-temp-path=/var/cache/nginx/client_temp \
24+ --http-proxy-temp-path=/var/cache/nginx/proxy_temp \
25+ --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp \
26+ --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp \
27+ --http-scgi-temp-path=/var/cache/nginx/scgi_temp \
28+ --user=nginx \
29+ --group=nginx \
30+ --with-http_ssl_module \
31+ --with-http_realip_module \
32+ --with-http_addition_module \
33+ --with-http_sub_module \
34+ --with-http_dav_module \
35+ --with-http_flv_module \
36+ --with-http_mp4_module \
37+ --with-http_gunzip_module \
38+ --with-http_gzip_static_module \
39+ --with-http_random_index_module \
40+ --with-http_secure_link_module \
41+ --with-http_stub_status_module \
42+ --with-http_auth_request_module \
43+ --with-http_xslt_module=dynamic \
44+ --with-http_image_filter_module=dynamic \
45+ --with-http_geoip_module=dynamic \
46+ --with-http_perl_module=dynamic \
47+ --with-threads \
48+ --with-stream \
49+ --with-stream_ssl_module \
50+ --with-http_slice_module \
51+ --with-mail \
52+ --with-mail_ssl_module \
53+ --with-file-aio \
54+ --with-http_v2_module \
55+ --with-ipv6 \
56+ "
57+ ENV NGINX_CONFIG_MODSECURITY=" --add-module=$WORKING_DIRECTORY/ModSecurity/nginx/modsecurity "
58+ ENV NGINX_CONFIG_EXTRA_MODULES=" --with-http_realip_module --with-http_ssl_module "
1759ENV LC_ALL=C
1860
1961# 1 Install required dependencies
2062# 2 Compile Mod Security
2163# 3 Get Mod security configs
2264# 4 Compile Nginx
2365# 5 Clean solution
24- RUN apk update && \
66+ RUN \
67+ addgroup -S nginx && \
68+ adduser -D -S -h /var/cache/nginx -s /sbin/nologin -G nginx nginx && \
69+ apk update && \
2570 echo "#### Install required dependencies ####" && \
26- apk add build-base linux-headers bash git pcre-dev unzip libxml2 libxml2-dev wget openssl-dev libtool m4 autoconf automake curl apache2-dev zlib-dev && \
71+ apk add --no-cache \
72+ build-base \
73+ linux-headers \
74+ bash \
75+ git \
76+ pcre-dev \
77+ unzip \
78+ libxml2 \
79+ libxml2-dev \
80+ wget \
81+ openssl-dev \
82+ libtool \
83+ m4 \
84+ autoconf \
85+ automake \
86+ curl \
87+ gd-dev \
88+ geoip-dev \
89+ perl-dev \
90+ apache2-dev \
91+ zlib-dev \
92+ libxslt-dev && \
2793 echo "#### Compile Mod Security ####" && \
2894 git clone https://github.com/SpiderLabs/ModSecurity.git && \
2995 cd ModSecurity && \
@@ -48,17 +114,16 @@ RUN apk update && \
48114 wget http://nginx.org/download/nginx-${NGINX_VERSION}.tar.gz && \
49115 tar -xvzf nginx-${NGINX_VERSION}.tar.gz && \
50116 cd nginx-${NGINX_VERSION}/ && \
51- ./configure $NGINX_ADD_MODULES $NGINX_EXTRA_MODULES && \
117+ ./configure $NGINX_BASE_CONFIG $NGINX_CONFIG_MODSECURITY $NGINX_CONFIG_EXTRA_MODULES && \
52118 make && \
53119 make install && \
120+ rm /etc/nginx/nginx.conf && \
54121 cd .. && \
55122 echo "#### Clean solution ####" && \
56123 apk del build-base linux-headers git autoconf automake && \
57124 rm -rf $WORKING_DIRECTORY modsecurity.conf-recommended nginx-${NGINX_VERSION}.tar.gz nginx-${NGINX_VERSION} owasp-modsecurity-crs.tar.gz
58125
59- # Link Nginx and clean solution
60- RUN ln -s /usr/local/nginx/sbin/nginx /usr/bin/nginx && \
61- cp /usr/local/nginx/conf/*.* /etc/nginx/
126+
62127# Set workdir
63128WORKDIR /etc/nginx
64129
@@ -69,10 +134,11 @@ RUN nginx -V
69134RUN apk add openssl && \
70135 rm -rf /etc/nginx/conf.d/* && \
71136 mkdir -p /etc/nginx/external
72- RUN sed -i 's/access_log.*/access_log \/ dev\/ stdout;/g' /etc/nginx/nginx.conf; \
73- sed -i 's/error_log.*/error_log \/ dev\/ stdout info;/g' /etc/nginx/nginx.conf;
137+ ADD nginx.conf /etc/nginx/nginx.conf
74138ADD basic.conf /etc/nginx/conf.d/basic.conf
75139ADD ssl.conf /etc/nginx/conf.d/ssl.conf
140+ RUN sed -i 's/access_log.*/access_log \/ dev\/ stdout;/g' /etc/nginx/nginx.conf; \
141+ sed -i 's/error_log.*/error_log \/ dev\/ stdout info;/g' /etc/nginx/nginx.conf;
76142ADD entrypoint.sh /opt/entrypoint.sh
77143RUN chmod a+x /opt/entrypoint.sh
78144ENTRYPOINT ["/opt/entrypoint.sh" ]
0 commit comments