Skip to content

Commit 909a0bb

Browse files
authored
Add the zstd module (#154)
* Add the zstd module Resolves #132 * wip * Include quickjs engine to njs * Update formatting * Update nginx.conf: enable the zstd compression * CI - expect the resource to be compressed using zstd
1 parent 88dedd4 commit 909a0bb

File tree

4 files changed

+37
-18
lines changed

4 files changed

+37
-18
lines changed

Diff for: .github/workflows/dockerimage.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ jobs:
7070
curl -v --compressed localhost:8888 2>&1 | tee /tmp/out
7171
7272
grep --fixed-strings --invert-match -i '< Server: nginx' /tmp/out > /dev/null
73-
grep --fixed-strings '< Content-Encoding: br' /tmp/out
73+
grep --fixed-strings '< Content-Encoding: zstd' /tmp/out
7474
grep --fixed-strings '<p>It works!</p>' /tmp/out
7575
7676

Diff for: Dockerfile

+25-14
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ ARG HEADERS_MORE_VERSION=0.37
2020
# https://github.com/leev/ngx_http_geoip2_module/releases
2121
ARG GEOIP2_VERSION=3.4
2222

23+
# https://github.com/tokers/zstd-nginx-module/releases
24+
ARG ZSTD_VERSION=0.1.1
25+
2326
# NGINX UID / GID
2427
ARG NGINX_USER_UID=100
2528
ARG NGINX_GROUP_GID=101
@@ -77,6 +80,7 @@ ARG CONFIG="\
7780
--add-module=/usr/src/ngx_brotli \
7881
--add-module=/usr/src/headers-more-nginx-module-$HEADERS_MORE_VERSION \
7982
--add-module=/usr/src/njs/nginx \
83+
--add-module=/usr/src/zstd \
8084
--add-dynamic-module=/usr/src/ngx_http_geoip2_module \
8185
"
8286

@@ -88,35 +92,36 @@ ARG NGX_BROTLI_COMMIT
8892
ARG HEADERS_MORE_VERSION
8993
ARG NJS_COMMIT
9094
ARG GEOIP2_VERSION
95+
ARG ZSTD_VERSION
9196
ARG NGINX_USER_UID
9297
ARG NGINX_GROUP_GID
9398
ARG CONFIG
9499

95100
RUN \
96101
apk add --no-cache --virtual .build-deps \
97102
gcc \
103+
gd-dev \
104+
geoip-dev \
105+
gnupg \
106+
go \
98107
libc-dev \
108+
libxslt-dev \
109+
linux-headers \
99110
make \
111+
mercurial \
100112
musl-dev \
101-
go \
102113
ninja \
103-
mercurial \
104114
openssl-dev \
105115
pcre-dev \
106-
zlib-dev \
107-
linux-headers \
108-
gnupg \
109-
libxslt-dev \
110-
gd-dev \
111-
geoip-dev \
112116
perl-dev \
117+
zlib-dev \
113118
&& apk add --no-cache --virtual .brotli-build-deps \
114119
autoconf \
115-
libtool \
116120
automake \
117-
git \
118-
g++ \
119121
cmake \
122+
g++ \
123+
git \
124+
libtool \
120125
&& apk add --no-cache --virtual .geoip2-build-deps \
121126
libmaxminddb-dev \
122127
&& apk add --no-cache --virtual .njs-build-deps \
@@ -127,6 +132,8 @@ RUN \
127132
pcre-dev \
128133
readline-dev \
129134
zlib-dev \
135+
&& apk add --no-cache --virtual .zstd-build-deps \
136+
zstd-dev \
130137
&& git config --global init.defaultBranch master
131138

132139
WORKDIR /usr/src/
@@ -171,6 +178,10 @@ RUN \
171178
echo "Downloading ngx_http_geoip2_module ..." \
172179
&& git clone --depth 1 --branch ${GEOIP2_VERSION} https://github.com/leev/ngx_http_geoip2_module /usr/src/ngx_http_geoip2_module
173180

181+
RUN \
182+
echo "Downloading zstd-nginx-module ..." \
183+
&& git clone --depth 1 --branch ${ZSTD_VERSION} https://github.com/tokers/zstd-nginx-module.git /usr/src/zstd
184+
174185
RUN \
175186
echo "Cloning and configuring quickjs ..." \
176187
&& cd /usr/src \
@@ -197,9 +208,9 @@ ARG LD_OPT='-Wl,-Bsymbolic-functions -flto=auto -ffat-lto-objects -flto=auto -L
197208
RUN \
198209
echo "Building nginx ..." \
199210
&& mkdir -p /var/run/nginx/ \
200-
&& cd /usr/src/nginx-$NGINX_VERSION \
201-
&& ./auto/configure $CONFIG --with-cc-opt="$CC_OPT" --with-ld-opt="$LD_OPT" \
202-
&& make -j"$(getconf _NPROCESSORS_ONLN)"
211+
&& cd /usr/src/nginx-$NGINX_VERSION \
212+
&& ./auto/configure $CONFIG --with-cc-opt="$CC_OPT" --with-ld-opt="$LD_OPT" \
213+
&& make -j"$(getconf _NPROCESSORS_ONLN)"
203214

204215
RUN \
205216
cd /usr/src/nginx-$NGINX_VERSION \

Diff for: nginx.conf

+7-1
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,16 @@ http {
4646
more_set_headers "Content-Security-Policy: object-src 'none'; frame-ancestors 'self'; form-action 'self'; block-all-mixed-content; sandbox allow-forms allow-same-origin allow-scripts allow-popups allow-downloads; base-uri 'self';";
4747

4848
# enable response compression
49-
gzip on;
49+
gzip on;
50+
51+
# https://github.com/google/ngx_brotli#configuration-directives
5052
brotli on;
5153
brotli_static on;
5254

55+
# https://github.com/tokers/zstd-nginx-module#directives
56+
zstd on;
57+
zstd_static on;
58+
5359
include /etc/nginx/conf.d/*.conf;
5460
}
5561

Diff for: readme.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
## What is this?
22
[![Docker Image CI](https://github.com/macbre/docker-nginx-http3/actions/workflows/dockerimage.yml/badge.svg)](https://github.com/macbre/docker-nginx-http3/actions/workflows/dockerimage.yml)
33

4-
Stable and up-to-date [nginx](https://nginx.org/en/CHANGES) with [QUIC + HTTP/3 support](https://nginx.org/en/docs/http/ngx_http_v3_module.html), [Google's `brotli` compression](https://github.com/google/ngx_brotli), [`njs` module](https://nginx.org/en/docs/njs/), [kTLS/sendfile support](https://delthas.fr/blog/2023/kernel-tls/) and [Grade A+ SSL config](https://ssl-config.mozilla.org/)
4+
Stable and up-to-date [nginx](https://nginx.org/en/CHANGES) with [QUIC + HTTP/3 support](https://nginx.org/en/docs/http/ngx_http_v3_module.html), [Google's `brotli` compression](https://github.com/google/ngx_brotli), [`zstd` compression](https://github.com/tokers/zstd-nginx-module), [`njs` module](https://nginx.org/en/docs/njs/), [kTLS/sendfile support](https://delthas.fr/blog/2023/kernel-tls/) and [Grade A+ SSL config](https://ssl-config.mozilla.org/)
55

66
## How to use this image
77
As this project is based on the official [nginx image](https://hub.docker.com/_/nginx/) look for instructions there. In addition to the standard configuration directives, you'll be able to use the brotli module specific ones, see [here for official documentation](https://github.com/google/ngx_brotli#configuration-directives)
@@ -21,6 +21,7 @@ docker pull ghcr.io/macbre/nginx-http3:latest
2121
* [built-in nginx modules](https://nginx.org/en/docs/)
2222
* [`headers-more-nginx-module`](https://github.com/openresty/headers-more-nginx-module#readme) - sets and clears HTTP request and response headers
2323
* [`ngx_brotli`](https://github.com/google/ngx_brotli#configuration-directives) - adds [brotli response compression](https://datatracker.ietf.org/doc/html/rfc7932)
24+
* [`zstd-nginx-module`](https://github.com/tokers/zstd-nginx-module#directives) - adds [Zstandard response compression](https://datatracker.ietf.org/doc/html/rfc8878)
2425
* [`ngx_http_geoip2_module`](https://github.com/leev/ngx_http_geoip2_module#download-maxmind-geolite2-database-optional) - creates variables with values from the maxmind geoip2 databases based on the client IP
2526
* [`njs` module](https://nginx.org/en/docs/njs/) - a subset of the JavaScript language that allows extending nginx functionality ([GitHub repository](https://github.com/nginx/njs))
2627

@@ -81,8 +82,9 @@ configure arguments:
8182
--add-module=/usr/src/ngx_brotli
8283
--add-module=/usr/src/headers-more-nginx-module-0.37
8384
--add-module=/usr/src/njs/nginx
85+
--add-module=/usr/src/zstd
8486
--add-dynamic-module=/usr/src/ngx_http_geoip2_module
85-
--with-cc-opt='-g -O2 -flto=auto -ffat-lto-objects -flto=auto -ffat-lto-objects -I /usr/src/quickjs'
87+
--with-cc-opt='-g -O2 -flto=auto -ffat-lto-objects -flto=auto -ffat-lto-objects -I /usr/src/quickjs'
8688
--with-ld-opt='-Wl,-Bsymbolic-functions -flto=auto -ffat-lto-objects -flto=auto -L /usr/src/quickjs'
8789
8890
$ docker run -it macbre/nginx-http3 njs -v

0 commit comments

Comments
 (0)