1
- FROM alpine:3.19 as nginx-builder
1
+ # This builds an http only nginx, with no extra modules, and no openssl
2
+ FROM alpine:3.20 AS nginx-builder
2
3
3
4
ENV NGINX_VERSION=1.26.1
4
- # pin nginx modules versions
5
- # see https://github.com/google/ngx_brotli/issues/120 for the lack of tags
6
- # BROKEN HASH: ENV NGX_BROTLI_COMMIT_HASH=63ca02abdcf79c9e788d2eedcc388d2335902e52
7
- ENV NGX_BROTLI_COMMIT_HASH=6e975bcb015f62e1f303054897783355e2a877dc
8
- # https://github.com/openresty/headers-more-nginx-module/tags
9
- ENV HEADERS_MORE_VERSION=v0.37
10
5
# releases can be signed by any key on this page https://nginx.org/en/pgp_keys.html
11
6
# so this might need to be updated for a new release
12
7
# available keys: mdounin, maxim, sb, thresh
13
8
# the "signing key" is used for linux packages, see https://trac.nginx.org/nginx/ticket/205
14
9
ENV PGP_SIGNING_KEY_OWNER=thresh
15
10
16
11
# install dependencies: here we use brotli-dev, newer brotli versions we can remove that and build it
17
- RUN apk add --no-cache git libc-dev pcre2-dev make gcc zlib-dev openssl-dev binutils gnupg cmake brotli-dev
12
+ RUN apk add --no-cache git libc-dev pcre2-dev make gcc binutils gnupg cmake brotli-dev
18
13
19
14
# create a builder user and group
20
15
RUN addgroup -S -g 3148 builder && adduser -D -S -G builder -u 3148 builder
@@ -23,8 +18,9 @@ WORKDIR /build
23
18
USER builder
24
19
25
20
# clone the nginx modules
26
- RUN git clone https://github.com/google/ngx_brotli && cd ngx_brotli && git reset --hard $NGX_BROTLI_COMMIT_HASH && cd ..
27
- RUN git clone --depth 1 -b $HEADERS_MORE_VERSION https://github.com/openresty/headers-more-nginx-module
21
+ RUN git clone --recurse-submodules https://github.com/google/ngx_brotli && cd ngx_brotli/deps/brotli && mkdir out && cd out \
22
+ && cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF -DCMAKE_C_FLAGS="-Ofast -m64 -march=native -mtune=native -flto -funroll-loops -ffunction-sections -fdata-sections -Wl,--gc-sections" -DCMAKE_CXX_FLAGS="-Ofast -m64 -march=native -mtune=native -flto -funroll-loops -ffunction-sections -fdata-sections -Wl,--gc-sections" -DCMAKE_INSTALL_PREFIX=./installed .. \
23
+ && cmake --build . --config Release --target brotlienc && cd ../../../..
28
24
29
25
# now start the build
30
26
# get nginx source
@@ -40,6 +36,8 @@ RUN if [ "$TARGETPLATFORM" = "linux/amd64" ]; then gpg --verify nginx.tgz.asc; f
40
36
# all good now untar and build!
41
37
RUN tar xzf nginx.tgz
42
38
WORKDIR /build/nginx-$NGINX_VERSION
39
+ # change the hardcoded Server header value
40
+ RUN sed -i 's/"Server: nginx" CRLF/"Server: d" CRLF/' src/http/ngx_http_header_filter_module.c
43
41
# Compilation flags
44
42
# -g0: Disable debugging symbols generation (decreases binary size)
45
43
# -O3: Enable aggressive optimization level 3 (improves code execution speed)
@@ -57,29 +55,27 @@ WORKDIR /build/nginx-$NGINX_VERSION
57
55
RUN ./configure \
58
56
--prefix=/var/lib/nginx \
59
57
--sbin-path=/usr/sbin/nginx \
60
- --with-cc-opt='-g0 -O3 -fstack-protector-strong -flto -pie --param=ssp-buffer-size=4 -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 -Wl,-z,relro,-z,now -Wl,-z,noexecstack -fPIC' \
58
+ --with-cc-opt='-g0 -O3 -fstack-protector-strong -flto -pie --param=ssp-buffer-size=4 -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 -Wl,-z,relro,-z,now -Wl,-z,noexecstack -fPIC -static -static-libgcc' \
59
+ --with-ld-opt='-static' \
61
60
--modules-path=/usr/lib/nginx/modules \
62
61
--conf-path=/etc/nginx/nginx.conf \
63
- --pid-path=/run /nginx.pid \
62
+ --pid-path=/nginx /nginx.pid \
64
63
--error-log-path=/var/log/nginx/error.log \
65
64
--http-log-path=/var/log/nginx/access.log \
66
- --lock-path=/run /nginx.lock \
67
- --http-client-body-temp-path=/run /nginx-client_body \
68
- --http-fastcgi-temp-path=/run /nginx-fastcgi \
69
- --user=nginx \
70
- --group=nginx \
65
+ --lock-path=/nginx /nginx.lock \
66
+ --http-client-body-temp-path=/nginx /nginx-client_body \
67
+ --http-fastcgi-temp-path=/nginx /nginx-fastcgi \
68
+ --user=nobody \
69
+ --group=nobody \
71
70
--with-threads \
72
- --with-http_ssl_module \
73
- --with-http_v2_module \
74
71
--with-http_realip_module \
75
- --with-http_gzip_static_module \
76
72
--with-http_stub_status_module \
77
73
--add-module=/build/ngx_brotli \
78
- --add-module=/build/headers-more-nginx-module \
79
74
--without-http_autoindex_module \
80
75
--without-http_browser_module \
81
76
--without-http_empty_gif_module \
82
77
--without-http_geo_module \
78
+ --without-http_gzip_module \
83
79
--without-http_limit_conn_module \
84
80
--without-http_limit_req_module \
85
81
--without-http_map_module \
@@ -97,3 +93,19 @@ RUN ./configure \
97
93
98
94
USER root
99
95
RUN make install
96
+
97
+ FROM alpine:3.20
98
+ COPY --from=nginx-builder /usr/sbin/nginx /usr/sbin/nginx
99
+ COPY --from=nginx-builder /etc/nginx/mime.types /etc/nginx/mime.types
100
+ COPY --from=nginx-builder /etc/nginx/fastcgi.conf /etc/nginx/fastcgi.conf
101
+ COPY --from=nginx-builder /var/lib/nginx /var/lib/nginx
102
+ # create the log folder and make the logfiles links to stdout/stderr so docker logs will catch it
103
+ RUN mkdir -p /var/log/nginx \
104
+ && ln -sf /dev/stdout /var/log/nginx/access.log \
105
+ && ln -sf /dev/stderr /var/log/nginx/error.log
106
+ ADD nginx.conf /etc/nginx/nginx.conf
107
+ ADD common.conf /etc/nginx/common.conf
108
+ RUN mkdir /etc/nginx/conf.d
109
+ RUN mkdir /nginx && chown nobody:nobody /nginx
110
+ USER nobody
111
+ ENTRYPOINT ["nginx" ]
0 commit comments