Skip to content

Commit

Permalink
Add the zstd module (#154)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
macbre authored Nov 25, 2024
1 parent 88dedd4 commit 909a0bb
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/dockerimage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ jobs:
curl -v --compressed localhost:8888 2>&1 | tee /tmp/out
grep --fixed-strings --invert-match -i '< Server: nginx' /tmp/out > /dev/null
grep --fixed-strings '< Content-Encoding: br' /tmp/out
grep --fixed-strings '< Content-Encoding: zstd' /tmp/out
grep --fixed-strings '<p>It works!</p>' /tmp/out
Expand Down
39 changes: 25 additions & 14 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ ARG HEADERS_MORE_VERSION=0.37
# https://github.com/leev/ngx_http_geoip2_module/releases
ARG GEOIP2_VERSION=3.4

# https://github.com/tokers/zstd-nginx-module/releases
ARG ZSTD_VERSION=0.1.1

# NGINX UID / GID
ARG NGINX_USER_UID=100
ARG NGINX_GROUP_GID=101
Expand Down Expand Up @@ -77,6 +80,7 @@ ARG CONFIG="\
--add-module=/usr/src/ngx_brotli \
--add-module=/usr/src/headers-more-nginx-module-$HEADERS_MORE_VERSION \
--add-module=/usr/src/njs/nginx \
--add-module=/usr/src/zstd \
--add-dynamic-module=/usr/src/ngx_http_geoip2_module \
"

Expand All @@ -88,35 +92,36 @@ ARG NGX_BROTLI_COMMIT
ARG HEADERS_MORE_VERSION
ARG NJS_COMMIT
ARG GEOIP2_VERSION
ARG ZSTD_VERSION
ARG NGINX_USER_UID
ARG NGINX_GROUP_GID
ARG CONFIG

RUN \
apk add --no-cache --virtual .build-deps \
gcc \
gd-dev \
geoip-dev \
gnupg \
go \
libc-dev \
libxslt-dev \
linux-headers \
make \
mercurial \
musl-dev \
go \
ninja \
mercurial \
openssl-dev \
pcre-dev \
zlib-dev \
linux-headers \
gnupg \
libxslt-dev \
gd-dev \
geoip-dev \
perl-dev \
zlib-dev \
&& apk add --no-cache --virtual .brotli-build-deps \
autoconf \
libtool \
automake \
git \
g++ \
cmake \
g++ \
git \
libtool \
&& apk add --no-cache --virtual .geoip2-build-deps \
libmaxminddb-dev \
&& apk add --no-cache --virtual .njs-build-deps \
Expand All @@ -127,6 +132,8 @@ RUN \
pcre-dev \
readline-dev \
zlib-dev \
&& apk add --no-cache --virtual .zstd-build-deps \
zstd-dev \
&& git config --global init.defaultBranch master

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

RUN \
echo "Downloading zstd-nginx-module ..." \
&& git clone --depth 1 --branch ${ZSTD_VERSION} https://github.com/tokers/zstd-nginx-module.git /usr/src/zstd

RUN \
echo "Cloning and configuring quickjs ..." \
&& cd /usr/src \
Expand All @@ -197,9 +208,9 @@ ARG LD_OPT='-Wl,-Bsymbolic-functions -flto=auto -ffat-lto-objects -flto=auto -L
RUN \
echo "Building nginx ..." \
&& mkdir -p /var/run/nginx/ \
&& cd /usr/src/nginx-$NGINX_VERSION \
&& ./auto/configure $CONFIG --with-cc-opt="$CC_OPT" --with-ld-opt="$LD_OPT" \
&& make -j"$(getconf _NPROCESSORS_ONLN)"
&& cd /usr/src/nginx-$NGINX_VERSION \
&& ./auto/configure $CONFIG --with-cc-opt="$CC_OPT" --with-ld-opt="$LD_OPT" \
&& make -j"$(getconf _NPROCESSORS_ONLN)"

RUN \
cd /usr/src/nginx-$NGINX_VERSION \
Expand Down
8 changes: 7 additions & 1 deletion nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,16 @@ http {
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';";

# enable response compression
gzip on;
gzip on;

# https://github.com/google/ngx_brotli#configuration-directives
brotli on;
brotli_static on;

# https://github.com/tokers/zstd-nginx-module#directives
zstd on;
zstd_static on;

include /etc/nginx/conf.d/*.conf;
}

6 changes: 4 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
## What is this?
[![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)

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/)
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/)

## How to use this image
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)
Expand All @@ -21,6 +21,7 @@ docker pull ghcr.io/macbre/nginx-http3:latest
* [built-in nginx modules](https://nginx.org/en/docs/)
* [`headers-more-nginx-module`](https://github.com/openresty/headers-more-nginx-module#readme) - sets and clears HTTP request and response headers
* [`ngx_brotli`](https://github.com/google/ngx_brotli#configuration-directives) - adds [brotli response compression](https://datatracker.ietf.org/doc/html/rfc7932)
* [`zstd-nginx-module`](https://github.com/tokers/zstd-nginx-module#directives) - adds [Zstandard response compression](https://datatracker.ietf.org/doc/html/rfc8878)
* [`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
* [`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))

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

0 comments on commit 909a0bb

Please sign in to comment.