-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
187 lines (181 loc) · 9.4 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
# Metadata and base image configuration
ARG DISTRO=alpine
ARG DISTRO_VARIANT=3.20
FROM docker.io/focela/${DISTRO}:${DISTRO_VARIANT}
# Metadata for the image
LABEL maintainer="Focela Technologies (https://github.com/focela)" \
description="Highly customizable Dockerized web server with Nginx."
# Build-time arguments and environment variables
ARG NGINX_VERSION
# Define environment variables
ENV NGINX_VERSION=${NGINX_VERSION:-"1.27.3"} \
NGINX_MODULE_AUTH_LDAP_VERSION=241200eac8e4acae74d353291bd27f79e5ca3dc4 \
NGINX_MODULE_BROTLI_VERSION=6e975bcb015f62e1f303054897783355e2a877dc \
NGINX_MODULE_COOKIE_FLAG_VERSION=c4ff449318474fbbb4ba5f40cb67ccd54dc595d4 \
NGINX_MODULE_MORE_HEADERS_VERSION=f8f80997f19a41dc4181987544b9f3570cc3d6da \
NGINX_USER=nginx \
NGINX_GROUP=www-data \
NGINX_WEBROOT=/www/html \
IMAGE_NAME="focela/nginx" \
IMAGE_REPO_URL="https://github.com/focela/nginx/"
# Determine which SSL library to use based on the Alpine version
RUN alpine_ssl="openssl"; \
case "$(cat /etc/os-release | grep VERSION_ID | cut -d = -f 2 | cut -d . -f 1,2 | cut -d _ -f 1)" in \
3.5 | 3.6 | 3.7 | 3.8 | 3.9 | 3.10 | 3.11 | 3.12 | 3.13 | 3.14 | 3.15 | 3.16 ) \
alpine_ssl="libressl" ;; \
3.17* | 3.18* | 3.19* | 3.20* | 3.21* ) \
alpine_ssl="openssl" ;; \
*) \
echo "Unsupported Alpine version. Defaulting to OpenSSL."; \
alpine_ssl="openssl" ;; \
esac ; \
# Setup necessary groups and users
source /assets/functions/00-container && \
set -x && \
sed -i "/www-data/d" /etc/group* && \
addgroup -S -g 82 ${NGINX_GROUP} && \
adduser -D -S -h /var/cache/nginx -s /sbin/nologin -G ${NGINX_GROUP} -g "${NGINX_USER}" -u 80 ${NGINX_USER} && \
# Update and install dependencies
package update && \
package upgrade && \
package install .nginx-build-deps \
gcc \
gd-dev \
geoip-dev \
libc-dev \
${alpine_ssl}-dev \
libxslt-dev \
linux-headers \
make \
pcre-dev \
perl-dev \
tar \
zlib-dev && \
package install .brotli-build-deps \
autoconf \
automake \
cmake \
g++ \
git \
libtool && \
package install .auth-ldap-build-deps \
openldap-dev && \
# Set up directories and permissions
mkdir -p /www /var/log/nginx && \
chown -R ${NGINX_USER}:${NGINX_GROUP} /var/log/nginx && \
# Clone required Nginx modules
clone_git_repo https://github.com/openresty/headers-more-nginx-module ${NGINX_MODULE_MORE_HEADERS_VERSION} && \
clone_git_repo https://github.com/kvspb/nginx-auth-ldap ${NGINX_MODULE_AUTH_LDAP_VERSION} && \
clone_git_repo https://github.com/google/ngx_brotli ${NGINX_MODULE_BROTLI_VERSION} && \
clone_git_repo https://github.com/AirisX/nginx_cookie_flag_module ${NGINX_MODULE_COOKIE_FLAG_VERSION} && \
# Download, configure, and build Nginx from source
mkdir -p /usr/src/nginx && \
curl -sSL http://nginx.org/download/nginx-${NGINX_VERSION}.tar.gz | \
tar xvfz - --strip 1 -C /usr/src/nginx && \
cd /usr/src/nginx && \
./configure \
--prefix=/etc/nginx \
--sbin-path=/usr/sbin/nginx \
--modules-path=/usr/lib/nginx/modules \
--conf-path=/etc/nginx/nginx.conf \
--error-log-path=/dev/null \
--http-log-path=/dev/null \
--pid-path=/var/run/nginx.pid \
--lock-path=/var/run/nginx.lock \
--http-client-body-temp-path=/var/cache/nginx/client_temp \
--http-proxy-temp-path=/var/cache/nginx/proxy_temp \
--http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp \
--http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp \
--http-scgi-temp-path=/var/cache/nginx/scgi_temp \
--user=${NGINX_USER} \
--group=${NGINX_GROUP} \
--add-module=${GIT_REPO_SRC_HEADERS_MORE_NGINX_MODULE} \
--add-module=${GIT_REPO_SRC_NGINX_AUTH_LDAP} \
--add-module=${GIT_REPO_SRC_NGINX_COOKIE_FLAG_MODULE} \
--add-module=${GIT_REPO_SRC_NGX_BROTLI} \
--with-cc-opt='-Wno-vla-parameter' \
--with-compat \
--with-file-aio \
--with-http_addition_module \
--with-http_auth_request_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_geoip_module=dynamic \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_image_filter_module=dynamic \
--with-http_mp4_module \
--with-http_perl_module=dynamic \
--with-http_random_index_module \
--with-http_realip_module \
--with-http_secure_link_module \
--with-http_slice_module \
--with-http_ssl_module \
--with-http_stub_status_module \
--with-http_sub_module \
--with-http_v2_module \
--with-http_xslt_module=dynamic \
--with-mail \
--with-mail_ssl_module \
--with-stream \
--with-stream_geoip_module=dynamic \
--with-stream_realip_module \
--with-stream_ssl_module \
--with-stream_ssl_preread_module \
--with-threads && \
make -j$(getconf _NPROCESSORS_ONLN) && \
make install && \
# Finalize Nginx setup by preparing directories, default files, and cleaning binaries
rm -rf /etc/nginx/html/ && \
mkdir -p /etc/nginx/sites.enabled && \
mkdir -p /etc/nginx/sites.available && \
mkdir -p /usr/share/nginx/html/ && \
install -m644 html/index.html /usr/share/nginx/html/ && \
install -m644 html/50x.html /usr/share/nginx/html/ && \
ln -s ../../usr/lib/nginx/modules /etc/nginx/modules && \
strip /usr/sbin/nginx* && \
strip /usr/lib/nginx/modules/*.so && \
runDeps="$( \
scanelf --needed --nobanner /usr/sbin/nginx /usr/lib/nginx/modules/*.so /tmp/envsubst \
| awk '{ gsub(/,/, "\nso:", $2); print "so:" $2 }' \
| sort -u \
| xargs -r package info --installed \
| sort -u \
)" && \
package install .nginx-run-deps \
$runDeps \
apache2-utils \
inotify-tools \
libldap && \
# Set up directories and download configuration files for bad bot blocker
mkdir -p /etc/nginx/snippets/blockbots /etc/nginx/snippets/blockbots-custom && \
curl -sL https://raw.githubusercontent.com/mitchellkrogza/nginx-ultimate-bad-bot-blocker/master/bots.d/bad-referrer-words.conf -o /etc/nginx/snippets/blockbots/bad-referrer-words.conf && \
curl -sL https://raw.githubusercontent.com/mitchellkrogza/nginx-ultimate-bad-bot-blocker/master/bots.d/bad-referrers.conf -o /etc/nginx/snippets/blockbots/bad-referrers.conf && \
curl -sL https://raw.githubusercontent.com/mitchellkrogza/nginx-ultimate-bad-bot-blocker/master/bots.d/blacklist-ips.conf -o /etc/nginx/snippets/blockbots/blacklist-ips.conf && \
curl -sL https://raw.githubusercontent.com/mitchellkrogza/nginx-ultimate-bad-bot-blocker/master/bots.d/blacklist-user-agents.conf -o /etc/nginx/snippets/blockbots/blacklist-user-agents.conf && \
curl -sL https://raw.githubusercontent.com/mitchellkrogza/nginx-ultimate-bad-bot-blocker/master/bots.d/blockbots.conf -o /etc/nginx/snippets/blockbots/blockbots.conf && \
curl -sL https://raw.githubusercontent.com/mitchellkrogza/nginx-ultimate-bad-bot-blocker/master/bots.d/custom-bad-referrers.conf -o /etc/nginx/snippets/blockbots/custom-bad-referrers.conf && \
curl -sL https://raw.githubusercontent.com/mitchellkrogza/nginx-ultimate-bad-bot-blocker/master/bots.d/ddos.conf -o /etc/nginx/snippets/blockbots/ddos.conf && \
curl -sL https://raw.githubusercontent.com/mitchellkrogza/nginx-ultimate-bad-bot-blocker/master/bots.d/whitelist-domains.conf -o /etc/nginx/snippets/blockbots/whitelist-domains.conf && \
curl -sL https://raw.githubusercontent.com/mitchellkrogza/nginx-ultimate-bad-bot-blocker/master/bots.d/whitelist-ips.conf -o /etc/nginx/snippets/blockbots/whitelist-ips.conf && \
curl -sL https://raw.githubusercontent.com/mitchellkrogza/nginx-ultimate-bad-bot-blocker/master/conf.d/globalblacklist.conf -o /etc/nginx/snippets/blockbots/globalblacklist.conf && \
sed -i "s|/etc/nginx/bots.d/|/etc/nginx/snippets/blockbots/|g" /etc/nginx/snippets/blockbots/globalblacklist.conf && \
sed -i "s|/etc/nginx/snippets/blockbots/bad-referrer-words.conf|/etc/nginx/snippets/blockbots-custom/bad-referrer-words.conf|g" /etc/nginx/snippets/blockbots/globalblacklist.conf && \
sed -i "s|/etc/nginx/snippets/blockbots/blacklist-ips.conf|/etc/nginx/snippets/blockbots-custom/blacklist-ips.conf|g" /etc/nginx/snippets/blockbots/globalblacklist.conf && \
sed -i "s|/etc/nginx/snippets/blockbots/blacklist-user-agents.conf|/etc/nginx/snippets/blockbots-custom/blacklist-user-agents.conf|g" /etc/nginx/snippets/blockbots/globalblacklist.conf && \
sed -i "s|/etc/nginx/snippets/blockbots/whitelist-domains.conf|/etc/nginx/snippets/blockbots-custom/whitelist-domains.conf|g" /etc/nginx/snippets/blockbots/globalblacklist.conf && \
sed -i "s|/etc/nginx/snippets/blockbots/whitelist-ips.conf|/etc/nginx/snippets/blockbots-custom/whitelist-ips.conf|g" /etc/nginx/snippets/blockbots/globalblacklist.conf && \
# Clean up build dependencies and temporary files
package remove \
.nginx-build-deps \
.brotli-build-deps \
.auth-ldap-build-deps && \
package cleanup && \
rm -rf \
/etc/nginx/*.default \
/usr/src/* \
/var/tmp/*
# Expose HTTP port
EXPOSE 80
# Copy installation scripts into the image
COPY install /