|
| 1 | +FROM rust:1.51.0-slim-buster AS builder |
| 2 | + |
| 3 | +LABEL maintainer="metowolf <i@i-meto.com>, akafeng <i@sjy.im>" |
| 4 | + |
| 5 | +ARG NGINX_VERSION="1.19.10" |
| 6 | +ARG NGINX_GPG_KEY="B0F4253373F8F6F510D42178520A9993A1C052F8" |
| 7 | +ARG NGINX_URL="https://nginx.org/download/nginx-${NGINX_VERSION}.tar.gz" |
| 8 | +ARG NGINX_PGP_URL="https://nginx.org/download/nginx-${NGINX_VERSION}.tar.gz.asc" |
| 9 | + |
| 10 | +# ARG NGINX_OTHER_PATCH="https://raw.githubusercontent.com/kn007/patch/master/nginx.patch" |
| 11 | +# ARG NGINX_USE_OPENSSL_CRYPTO_PATCH="https://raw.githubusercontent.com/kn007/patch/master/use_openssl_md5_sha1.patch" |
| 12 | +ARG NGINX_OTHER_WITH_QUIC_PATCH="https://raw.githubusercontent.com/kn007/patch/master/nginx_with_quic.patch" |
| 13 | +ARG NGINX_BORINGSSL_OCSP_PATCH="https://raw.githubusercontent.com/kn007/patch/master/Enable_BoringSSL_OCSP.patch" |
| 14 | + |
| 15 | +ARG ZLIB_URL="https://github.com/cloudflare/zlib.git" |
| 16 | + |
| 17 | +# ARG OPENSSL_VERSION="1.1.1k" |
| 18 | +# ARG OPENSSL_URL="https://www.openssl.org/source/openssl-$OPENSSL_VERSION.tar.gz" |
| 19 | +# ARG OPENSSL_EQUAL_PATCH="https://raw.githubusercontent.com/hakasenyang/openssl-patch/master/openssl-equal-1.1.1e-dev_ciphers.patch" |
| 20 | +# ARG OPENSSL_CHACHA_DRAFT_PATCH="https://raw.githubusercontent.com/CarterLi/openssl-patch/master/openssl-1.1.1i-chacha_draft.patch" |
| 21 | + |
| 22 | +ARG QUICHE_VERSION="0.8.0" |
| 23 | +ARG QUICHE_URL="https://github.com/cloudflare/quiche.git" |
| 24 | + |
| 25 | +ARG PCRE_VERSION="8.44" |
| 26 | +ARG PCRE_URL="https://ftp.pcre.org/pub/pcre/pcre-${PCRE_VERSION}.tar.gz" |
| 27 | + |
| 28 | +ARG LIBATOMIC_VERSION="7.6.10" |
| 29 | +ARG LIBATOMIC_URL="https://github.com/ivmai/libatomic_ops/releases/download/v${LIBATOMIC_VERSION}/libatomic_ops-${LIBATOMIC_VERSION}.tar.gz" |
| 30 | + |
| 31 | +ARG MODULE_BROTLI_URL="https://github.com/google/ngx_brotli.git" |
| 32 | + |
| 33 | +ARG MODULE_STICKY_URL="https://bitbucket.org/nginx-goodies/nginx-sticky-module-ng.git" |
| 34 | + |
| 35 | +ARG MODULE_HEADERS_MORE_VERSION="0.33" |
| 36 | +ARG MODULE_HEADERS_MORE_URL="https://github.com/openresty/headers-more-nginx-module/archive/refs/tags/v${MODULE_HEADERS_MORE_VERSION}.tar.gz" |
| 37 | + |
| 38 | +ARG MODULE_HTTP_FLV_URL="https://github.com/winshining/nginx-http-flv-module.git" |
| 39 | + |
| 40 | +ARG MODULE_FANCYINDEX_VERSION="0.5.1" |
| 41 | +ARG MODULE_FANCYINDEX_URL="https://github.com/aperezdc/ngx-fancyindex/releases/download/v${MODULE_FANCYINDEX_VERSION}/ngx-fancyindex-${MODULE_FANCYINDEX_VERSION}.tar.xz" |
| 42 | + |
| 43 | +ARG MODULE_SUBS_FILTER_URL="https://github.com/yaoweibin/ngx_http_substitutions_filter_module.git" |
| 44 | + |
| 45 | +ARG MODULE_GEOIP2_VERSION="3.3" |
| 46 | +ARG MODULE_GEOIP2_URL="https://github.com/leev/ngx_http_geoip2_module/archive/refs/tags/${MODULE_GEOIP2_VERSION}.tar.gz" |
| 47 | + |
| 48 | +RUN set -eux \ |
| 49 | + && apt-get update -qyy \ |
| 50 | + && apt-get install -qyy --no-install-recommends --no-install-suggests \ |
| 51 | + ca-certificates \ |
| 52 | + wget \ |
| 53 | + gnupg \ |
| 54 | + \ |
| 55 | + git \ |
| 56 | + file \ |
| 57 | + build-essential \ |
| 58 | + cmake \ |
| 59 | + libjemalloc-dev \ |
| 60 | + libxslt1-dev \ |
| 61 | + libgd-dev \ |
| 62 | + libgeoip-dev \ |
| 63 | + libmaxminddb-dev \ |
| 64 | + && rm -rf /var/lib/apt/lists/* /var/log/* \ |
| 65 | + \ |
| 66 | + && wget -O nginx.tar.gz ${NGINX_URL} \ |
| 67 | + && wget -O nginx.tar.gz.asc ${NGINX_PGP_URL} \ |
| 68 | + \ |
| 69 | + && export GNUPGHOME=$(mktemp -d); \ |
| 70 | + for key in ${NGINX_GPG_KEY}; do \ |
| 71 | + gpg --batch --keyserver ha.pool.sks-keyservers.net --keyserver-options timeout=10 --recv-keys ${key} || \ |
| 72 | + gpg --batch --keyserver hkp://ipv4.pool.sks-keyservers.net --keyserver-options timeout=10 --recv-keys ${key} || \ |
| 73 | + gpg --batch --keyserver hkp://pgp.mit.edu:80 --keyserver-options timeout=10 --recv-keys ${key}; \ |
| 74 | + done \ |
| 75 | + && gpg --batch --verify nginx.tar.gz.asc nginx.tar.gz \ |
| 76 | + && gpgconf --kill all \ |
| 77 | + \ |
| 78 | + && tar -xzC /usr/src/ -f nginx.tar.gz \ |
| 79 | + && rm -rf nginx* ${GNUPGHOME} |
| 80 | + |
| 81 | +RUN set -eux \ |
| 82 | + && cd /usr/src/nginx-${NGINX_VERSION}/ \ |
| 83 | + \ |
| 84 | + # zlib-cloudflare |
| 85 | + && git clone --depth 1 ${ZLIB_URL} \ |
| 86 | + && ( \ |
| 87 | + cd zlib/; \ |
| 88 | + make -f Makefile.in distclean \ |
| 89 | + ) \ |
| 90 | + # \ |
| 91 | + # OpenSSL |
| 92 | + # && wget -O openssl-${OPENSSL_VERSION}.tar.gz ${OPENSSL_URL} \ |
| 93 | + # && tar -xzf openssl-${OPENSSL_VERSION}.tar.gz \ |
| 94 | + # && ( \ |
| 95 | + # cd openssl-${OPENSSL_VERSION}/; \ |
| 96 | + # wget -O - "$OPENSSL_EQUAL_PATCH" | patch -p1; \ |
| 97 | + # wget -O - "$OPENSSL_CHACHA_DRAFT_PATCH" | patch -p1 \ |
| 98 | + # ) \ |
| 99 | + \ |
| 100 | + # quiche |
| 101 | + && git clone --branch ${QUICHE_VERSION} --depth=1 --recurse-submodules --shallow-submodules ${QUICHE_URL} \ |
| 102 | + \ |
| 103 | + # PCRE |
| 104 | + && wget -O pcre-${PCRE_VERSION}.tar.gz ${PCRE_URL} \ |
| 105 | + && tar -xzf pcre-${PCRE_VERSION}.tar.gz \ |
| 106 | + \ |
| 107 | + # libatomic_ops |
| 108 | + && wget -O libatomic_ops-${LIBATOMIC_VERSION}.tar.gz ${LIBATOMIC_URL} \ |
| 109 | + && tar -xzf libatomic_ops-${LIBATOMIC_VERSION}.tar.gz \ |
| 110 | + && ( \ |
| 111 | + cd libatomic_ops-${LIBATOMIC_VERSION}/; \ |
| 112 | + ./configure; \ |
| 113 | + make -j "$(nproc)"; \ |
| 114 | + ln -s .libs/libatomic_ops.a src/libatomic_ops.a \ |
| 115 | + ) \ |
| 116 | + \ |
| 117 | + # ngx_brotli |
| 118 | + && git clone --depth=1 --recurse-submodules --shallow-submodules ${MODULE_BROTLI_URL} \ |
| 119 | + \ |
| 120 | + # nginx-sticky-module-ng |
| 121 | + && git clone --depth 1 ${MODULE_STICKY_URL} \ |
| 122 | + \ |
| 123 | + # headers-more-nginx |
| 124 | + && wget -O headers-more-nginx-module-${MODULE_HEADERS_MORE_VERSION}.tar.gz ${MODULE_HEADERS_MORE_URL} \ |
| 125 | + && tar -xzf headers-more-nginx-module-${MODULE_HEADERS_MORE_VERSION}.tar.gz \ |
| 126 | + \ |
| 127 | + # nginx-http-flv-module |
| 128 | + && git clone --depth 1 ${MODULE_HTTP_FLV_URL} \ |
| 129 | + \ |
| 130 | + # ngx-fancyindex |
| 131 | + && wget -O ngx-fancyindex-${MODULE_FANCYINDEX_VERSION}.tar.xz ${MODULE_FANCYINDEX_URL} \ |
| 132 | + && tar -xf ngx-fancyindex-${MODULE_FANCYINDEX_VERSION}.tar.xz \ |
| 133 | + \ |
| 134 | + # nginx_substitutions_filter |
| 135 | + && git clone --depth 1 ${MODULE_SUBS_FILTER_URL} \ |
| 136 | + \ |
| 137 | + # ngx_http_geoip2_module |
| 138 | + && wget -O ngx_http_geoip2_module-${MODULE_GEOIP2_VERSION}.tar.gz ${MODULE_GEOIP2_URL} \ |
| 139 | + && tar -xzf ngx_http_geoip2_module-${MODULE_GEOIP2_VERSION}.tar.gz |
| 140 | + |
| 141 | +RUN set -eux \ |
| 142 | + && cd /usr/src/nginx-${NGINX_VERSION}/ \ |
| 143 | + \ |
| 144 | + # && wget -O - ${NGINX_OTHER_PATCH} | patch -p1 \ |
| 145 | + # && wget -O - ${NGINX_USE_OPENSSL_CRYPTO_PATCH} | patch -p1 \ |
| 146 | + && wget -O - ${NGINX_OTHER_WITH_QUIC_PATCH} | patch -p1 \ |
| 147 | + && wget -O - ${NGINX_BORINGSSL_OCSP_PATCH} | patch -p1 \ |
| 148 | + \ |
| 149 | + && ./configure \ |
| 150 | + --prefix=/etc/nginx/ \ |
| 151 | + --sbin-path=/usr/sbin/nginx \ |
| 152 | + --modules-path=/usr/lib/nginx/modules/ \ |
| 153 | + --conf-path=/etc/nginx/nginx.conf \ |
| 154 | + --error-log-path=/var/log/nginx/error.log \ |
| 155 | + --http-log-path=/var/log/nginx/access.log \ |
| 156 | + --pid-path=/var/run/nginx.pid \ |
| 157 | + --lock-path=/var/run/nginx.lock \ |
| 158 | + --http-client-body-temp-path=/var/cache/nginx/client_temp/ \ |
| 159 | + --http-proxy-temp-path=/var/cache/nginx/proxy_temp/ \ |
| 160 | + --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp/ \ |
| 161 | + --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp/ \ |
| 162 | + --http-scgi-temp-path=/var/cache/nginx/scgi_temp/ \ |
| 163 | + --user=nginx \ |
| 164 | + --group=nginx \ |
| 165 | + --with-http_ssl_module \ |
| 166 | + --with-http_v2_module \ |
| 167 | + --with-http_realip_module \ |
| 168 | + --with-http_addition_module \ |
| 169 | + --with-http_sub_module \ |
| 170 | + --with-http_dav_module \ |
| 171 | + --with-http_flv_module \ |
| 172 | + --with-http_mp4_module \ |
| 173 | + --with-http_gunzip_module \ |
| 174 | + --with-http_gzip_static_module \ |
| 175 | + --with-http_random_index_module \ |
| 176 | + --with-http_secure_link_module \ |
| 177 | + --with-http_stub_status_module \ |
| 178 | + --with-http_auth_request_module \ |
| 179 | + --with-http_xslt_module \ |
| 180 | + --with-http_image_filter_module \ |
| 181 | + --with-http_geoip_module \ |
| 182 | + --with-http_slice_module \ |
| 183 | + --with-stream \ |
| 184 | + --with-stream_ssl_module \ |
| 185 | + --with-stream_ssl_preread_module \ |
| 186 | + --with-stream_realip_module \ |
| 187 | + --with-stream_geoip_module \ |
| 188 | + --with-mail \ |
| 189 | + --with-mail_ssl_module \ |
| 190 | + --with-file-aio \ |
| 191 | + --with-threads \ |
| 192 | + --with-compat \ |
| 193 | + --with-ld-opt="-Wl,-z,relro -Wl,-z,now -fPIC -ljemalloc -lrt" \ |
| 194 | + --with-cc-opt="-O3 -g -DTCP_FASTOPEN=23 -ffast-math -flto -fuse-ld=gold -fstack-protector-strong --param=ssp-buffer-size=4 -Wformat -Werror=format-security -fPIC -Wp,-D_FORTIFY_SOURCE=2 -Wno-deprecated-declarations" \ |
| 195 | + --with-zlib=/usr/src/nginx-${NGINX_VERSION}/zlib \ |
| 196 | + # --with-openssl=/usr/src/nginx-${NGINX_VERSION}/openssl-${OPENSSL_VERSION} \ |
| 197 | + # --with-openssl-opt="zlib enable-weak-ssl-ciphers enable-ec_nistp_64_gcc_128 -ljemalloc -Wl,-flto" \ |
| 198 | + --with-openssl=/usr/src/nginx-${NGINX_VERSION}/quiche/deps/boringssl \ |
| 199 | + --with-quiche=/usr/src/nginx-${NGINX_VERSION}/quiche \ |
| 200 | + --with-pcre=/usr/src/nginx-${NGINX_VERSION}/pcre-${PCRE_VERSION} \ |
| 201 | + --with-pcre-jit \ |
| 202 | + --with-libatomic=/usr/src/nginx-${NGINX_VERSION}/libatomic_ops-${LIBATOMIC_VERSION} \ |
| 203 | + --add-module=/usr/src/nginx-${NGINX_VERSION}/ngx_brotli \ |
| 204 | + --add-module=/usr/src/nginx-${NGINX_VERSION}/nginx-sticky-module-ng \ |
| 205 | + --add-module=/usr/src/nginx-${NGINX_VERSION}/headers-more-nginx-module-${MODULE_HEADERS_MORE_VERSION} \ |
| 206 | + --add-module=/usr/src/nginx-${NGINX_VERSION}/nginx-http-flv-module \ |
| 207 | + --add-module=/usr/src/nginx-${NGINX_VERSION}/ngx-fancyindex-${MODULE_FANCYINDEX_VERSION} \ |
| 208 | + --add-module=/usr/src/nginx-${NGINX_VERSION}/ngx_http_substitutions_filter_module \ |
| 209 | + --add-module=/usr/src/nginx-${NGINX_VERSION}/ngx_http_geoip2_module-${MODULE_GEOIP2_VERSION} \ |
| 210 | + --with-http_v2_hpack_enc \ |
| 211 | + --with-http_v3_module \ |
| 212 | + && make -j "$(nproc)" \ |
| 213 | + && make install \ |
| 214 | + \ |
| 215 | + && rm -rf /etc/nginx/html/ \ |
| 216 | + && mkdir -p /usr/share/nginx/html/ \ |
| 217 | + && install -m644 html/index.html /usr/share/nginx/html/ \ |
| 218 | + && install -m644 html/50x.html /usr/share/nginx/html/ \ |
| 219 | + \ |
| 220 | + && mkdir /etc/nginx/conf.d/ \ |
| 221 | + \ |
| 222 | + && rm -rf /usr/src/ \ |
| 223 | + && strip /usr/sbin/nginx \ |
| 224 | + && nginx -V |
| 225 | + |
| 226 | +COPY config/nginx.conf /etc/nginx/nginx.conf |
| 227 | +COPY config/nginx.vhost.default.conf /etc/nginx/conf.d/default.conf |
| 228 | +COPY config/logrotate /etc/nginx/logrotate |
| 229 | + |
| 230 | +###### |
| 231 | + |
| 232 | +FROM debian:buster-slim |
| 233 | + |
| 234 | +LABEL maintainer="metowolf <i@i-meto.com>, akafeng <i@sjy.im>" |
| 235 | + |
| 236 | +COPY --from=builder /usr/sbin/nginx /usr/sbin/nginx |
| 237 | +COPY --from=builder /etc/nginx/ /etc/nginx/ |
| 238 | +COPY --from=builder /usr/share/nginx/ /usr/share/nginx/ |
| 239 | + |
| 240 | +RUN set -eux \ |
| 241 | + && apt-get update -qyy \ |
| 242 | + && apt-get install -qyy --no-install-recommends --no-install-suggests \ |
| 243 | + cron \ |
| 244 | + logrotate \ |
| 245 | + libjemalloc2 \ |
| 246 | + libxslt1.1 \ |
| 247 | + libgd3 \ |
| 248 | + libgeoip1 \ |
| 249 | + libmaxminddb0 \ |
| 250 | + && rm -rf /var/lib/apt/lists/* /var/log/* \ |
| 251 | + \ |
| 252 | + && echo '1 0 * * * /usr/sbin/logrotate -f /etc/logrotate.conf' > /var/spool/cron/crontabs/root \ |
| 253 | + && addgroup --system nginx \ |
| 254 | + && adduser --system --disabled-login --ingroup nginx --no-create-home --home /nonexistent --shell /bin/false nginx \ |
| 255 | + && mkdir -p /usr/lib/nginx/modules/ \ |
| 256 | + && ln -s /usr/lib/nginx/modules/ /etc/nginx/modules \ |
| 257 | + \ |
| 258 | + && mkdir /var/cache/nginx/ \ |
| 259 | + \ |
| 260 | + && mkdir /var/log/nginx/ \ |
| 261 | + && ln -s /dev/stdout /var/log/nginx/access.log \ |
| 262 | + && ln -s /dev/stderr /var/log/nginx/error.log \ |
| 263 | + \ |
| 264 | + && mv /etc/nginx/logrotate /etc/logrotate.d/nginx \ |
| 265 | + && chmod 644 /etc/logrotate.d/nginx |
| 266 | + |
| 267 | +COPY docker-entrypoint.sh /usr/local/bin/ |
| 268 | +ENTRYPOINT ["docker-entrypoint.sh"] |
| 269 | + |
| 270 | +EXPOSE 80 443 |
| 271 | + |
| 272 | +STOPSIGNAL SIGQUIT |
| 273 | + |
| 274 | +CMD ["nginx", "-g", "daemon off;"] |
0 commit comments