Skip to content

Commit ca025ce

Browse files
committed
- added nginx docker image default modules
- added default nginx.conf - updated credits
1 parent 0a9542d commit ca025ce

File tree

3 files changed

+110
-12
lines changed

3 files changed

+110
-12
lines changed

Dockerfile

Lines changed: 77 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,87 @@ WORKDIR $WORKING_DIRECTORY
99

1010
# ENV build variables
1111
ENV LANG C.UTF-8
12-
ENV NPS_VERSION=1.9.32.2
1312
ENV NGINX_VERSION=1.11.1
1413
ENV 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 "
1759
ENV 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
63128
WORKDIR /etc/nginx
64129

@@ -69,10 +134,11 @@ RUN nginx -V
69134
RUN 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
74138
ADD basic.conf /etc/nginx/conf.d/basic.conf
75139
ADD 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;
76142
ADD entrypoint.sh /opt/entrypoint.sh
77143
RUN chmod a+x /opt/entrypoint.sh
78144
ENTRYPOINT ["/opt/entrypoint.sh"]

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,4 @@ Please note, that the Common Name (CN) is important and should be the FQDN to th
5050

5151
## Credits
5252

53-
This image was insiper by the work done on this DockerImage https://github.com/MarvAmBass/docker-nginx-ssl-secure
53+
This image was inspired by the work done on https://github.com/nginxinc/docker-nginx and https://github.com/MarvAmBass/docker-nginx-ssl-secure

nginx.conf

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
2+
user nginx;
3+
worker_processes 1;
4+
5+
error_log /var/log/nginx/error.log warn;
6+
pid /var/run/nginx.pid;
7+
8+
9+
events {
10+
worker_connections 1024;
11+
}
12+
13+
14+
http {
15+
include /etc/nginx/mime.types;
16+
default_type application/octet-stream;
17+
18+
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
19+
'$status $body_bytes_sent "$http_referer" '
20+
'"$http_user_agent" "$http_x_forwarded_for"';
21+
22+
access_log /var/log/nginx/access.log main;
23+
24+
sendfile on;
25+
#tcp_nopush on;
26+
27+
keepalive_timeout 65;
28+
29+
#gzip on;
30+
31+
include /etc/nginx/conf.d/*.conf;
32+
}

0 commit comments

Comments
 (0)