Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Brotli to NGINX #35

Merged
merged 3 commits into from
Jul 28, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 65 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,69 @@
# pull the Node.js Docker image
FROM nginx:mainline
ARG NGINX_VERSION="1.23.1"
ARG NGINX_NAME="nginx-${NGINX_VERSION}"

FROM debian as build

ARG NGINX_VERSION
ARG NGINX_NAME
ARG CONFIG=" --prefix=/etc/nginx \
--sbin-path=/usr/sbin/nginx \
--modules-path=/usr/lib/nginx/modules \
--conf-path=/etc/nginx/nginx.conf \
--http-log-path=/var/log/nginx/node-access.log \
--pid-path=/var/run/nginx.pid \
--lock-path=/var/run/nginx.lock \
--user=nginx --group=nginx \
--with-compat \
--with-file-aio \
--with-threads \
--with-http_addition_module \
--with-http_auth_request_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_mp4_module \
--with-http_random_index_module \
--with-http_realip_module \
--with-http_secure_link_module \
--with-http_slice_module \
--with-http_ssl_module \
--with-http_stub_status_module \
--with-http_sub_module \
--with-http_v2_module \
--with-mail \
--with-mail_ssl_module \
--with-stream \
--with-stream_realip_module \
--with-stream_ssl_module \
--with-stream_ssl_preread_module \
--with-compat \
--add-dynamic-module=/usr/src/ngx_brotli"

# Install dependencies
RUN apt-get update && apt-get install \
dpkg-dev build-essential gnupg2 \
git gcc cmake libpcre3 libpcre3-dev \
zlib1g zlib1g-dev openssl libssl-dev \
curl unzip wget libxslt-dev -y

WORKDIR /usr/src

# Install nginx + brotli module from source
RUN wget http://nginx.org/download/${NGINX_NAME}.tar.gz \
&& tar -xzvf ${NGINX_NAME}.tar.gz \
&& git clone https://github.com/google/ngx_brotli.git --recursive \
&& cd ${NGINX_NAME} \
&& ./configure $CONFIG \
&& make

FROM nginx:${NGINX_VERSION}

ARG NGINX_NAME

COPY --from=build /usr/src/${NGINX_NAME}/objs/ngx_http_brotli_filter_module.so /usr/lib/nginx/modules/
COPY --from=build /usr/src/${NGINX_NAME}/objs/ngx_http_brotli_static_module.so /usr/lib/nginx/modules/

# DEPENDENCIES
RUN curl -fsSL https://deb.nodesource.com/setup_16.x | bash -
# RUN curl -fsSL https://install.speedtest.net/app/cli/install.deb.sh | bash -
RUN curl -fsSL https://packagecloud.io/install/repositories/ookla/speedtest-cli/script.deb.sh | bash -
Expand Down
14 changes: 14 additions & 0 deletions container/nginx/nginx.conf
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
load_module /usr/lib/nginx/modules/ngx_http_brotli_filter_module.so;
load_module /usr/lib/nginx/modules/ngx_http_brotli_static_module.so;

user nginx;
worker_processes auto;

Expand All @@ -11,6 +14,17 @@ events {
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
brotli on;
brotli_types text/html text/richtext text/plain text/css text/x-script text/x-component
text/x-java-source text/x-markdown application/javascript application/x-javascript
text/javascript text/js image/x-icon image/vnd.microsoft.icon application/x-perl
application/x-httpd-cgi text/xml application/xml application/xml+rss application/vnd.api+json
application/x-protobuf application/json multipart/bag multipart/mixed application/xhtml+xml
font/ttf font/otf font/x-woff image/svg+xml application/vnd.ms-fontobject application/ttf
application/x-ttf application/otf application/x-otf application/truetype application/opentype
application/x-opentype application/font-woff application/eot application/font application/font-sfnt
application/wasm application/javascript-binast application/manifest+json application/ld+json
application/graphql+json application/geo+json;

log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
Expand Down