Open mpv945 opened 1 year ago
I see what you are saying. Besides the http
section, the main
stanza is currently:
pcre_jit on;
events {
worker_connections 1024;
}
You would like to inject some other text there, like a load_module
line. We do let you alter the build process with Docker build arguments, like RESTY_EVAL_POST_MAKE
. So you could use that arg to do something like:
docker build --build-arg RESTY_EVAL_POST_MAKE="echo 'load_module /etc/nginx/ngx_http_brotli_filter_module.so; load_module /etc/nginx/ngx_http_brotli_static_module.so;' >> /usr/local/openresty/nginx/conf/nginx.conf" -f focal/Dockerfile .
I didn't actually test that, but it's the idea.
You can also bind-mount your own nginx.conf
to /usr/local/openresty/nginx/conf/nginx.conf
. You are also bind-mounting the shared-objects or building it in a derived image?
Can docker-openresty support brotli compression?
I see the module ngx_brotli
. Is there any reason this isn't already in Nginx or OpenResty already? I generally don't add modules, but maybe we can add it to the -fat
images?
Offical docker image of PHP provides ENV like "PHPIZE_DEPS" and configured php sources, this make user build modules after base built possible:
distro_pm_like_apk add $BUILD_DEPS
install build deps, then tar -xf /usr/src/configured.tar.zst -C /usr/src/openresty
and cd into it, make their own modules ./configure $CONFIG_THINGS --add-dynamic-module=/path/to/whatever
distro_pm_like_apk del $BUILD_DEPS
Here's my demo Dockerfile for that
Since we donot have DEPS and CONFIG env, so this is rather fragile:
FROM openresty/openresty:1.21.4.1-4-rocky AS module-builder
# DONOT USE THIS IN PRODUCT!
WORKDIR /usr/src
RUN set -xeo pipefail ; \
dnf install -y git && \
wget https://openresty.org/download/openresty-1.21.4.1.tar.gz && \
mkdir openresty && \
tar --strip-components=1 -xf openresty-1.21.4.1.tar.gz -C openresty && \
git clone https://github.com/google/ngx_brotli /usr/src/ngx_brotli && \
git clone https://github.com/tokers/zstd-nginx-module /usr/src/zstd-nginx-module && \
:
RUN dnf install -yy epel-release && \
dnf install -yy ccache gcc make brotli-devel libzstd-devel \
# here we donot know which packages is used in building openresty
# so we have to dnf search and append "-devel" here
openresty-openssl111-devel openresty-pcre-devel openresty-zlib-devel
RUN set -xeo pipefail ; \
cd /usr/src/openresty/bundle/nginx-1.21.4 && \
# here we cannot get real configure args so we have to use nginx -V
# futhermore, --add-modules things make configure fail because wo donot have a "configurable" source for them
RESTY_CONFIG_OPTIONS="$(nginx -V 2>&1 | grep 'configure arguments:' | sed 's/^configure arguments://g' | sed -E 's/--add-module=[^ ]+ //g')" && \
eval "./configure $RESTY_CONFIG_OPTIONS --add-dynamic-module=/usr/src/ngx_brotli --add-dynamic-module=/usr/src/zstd-nginx-module" && \
make -j `nproc` modules && \
:
FROM openresty/openresty:1.21.4.1-4-rocky
RUN dnf install -yy brotli libzstd && \
dnf clean all
COPY --from=module-builder \
/usr/src/openresty/bundle/nginx-1.21.4/objs/ngx_http_brotli_filter_module.so \
/usr/src/openresty/bundle/nginx-1.21.4/objs/ngx_http_brotli_static_module.so \
/usr/src/openresty/bundle/nginx-1.21.4/objs/ngx_http_zstd_filter_module.so \
/usr/src/openresty/bundle/nginx-1.21.4/objs/ngx_http_zstd_static_module.so \
/usr/local/openresty/nginx/modules/
Brotli is dynamically compiled into a so file, and load_module /etc/nginx/ngx_http_brotli_filter_module.so; and load_module /etc/nginx/ngx_http_brotli_static_module.so are added at the beginning of nginx.conf