From 218e8abce773abfcd4d249a2500c381d345311ab Mon Sep 17 00:00:00 2001 From: enolal826 Date: Wed, 27 Jul 2022 20:01:10 +0200 Subject: [PATCH 1/3] Add Brotli to NGINX: first version --- Dockerfile | 68 ++++++++++++++++++++++++++++++++++++-- container/nginx/nginx.conf | 14 ++++++++ 2 files changed, 79 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index 470163b5..b9ac98e9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 - diff --git a/container/nginx/nginx.conf b/container/nginx/nginx.conf index 15a70bee..4fadf37d 100644 --- a/container/nginx/nginx.conf +++ b/container/nginx/nginx.conf @@ -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; @@ -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" ' From b5e1cb2f08275d21a9bac3af766633071280b30f Mon Sep 17 00:00:00 2001 From: Diego Rodriguez Baquero Date: Wed, 27 Jul 2022 16:48:38 -0500 Subject: [PATCH 2/3] Put inside custom node directives --- container/nginx/nginx.conf | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/container/nginx/nginx.conf b/container/nginx/nginx.conf index 4fadf37d..86cb817c 100644 --- a/container/nginx/nginx.conf +++ b/container/nginx/nginx.conf @@ -14,17 +14,6 @@ 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" ' @@ -49,6 +38,18 @@ http { open_file_cache max=10000 inactive=60m; open_file_cache_valid 60m; open_file_cache_min_uses 1; + + 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; # == end custom node directives == include /etc/nginx/conf.d/*.conf; From 2f5182e7cbe0c40672db93933ed4ea11dc20465a Mon Sep 17 00:00:00 2001 From: enolal826 Date: Thu, 28 Jul 2022 11:37:01 +0200 Subject: [PATCH 3/3] Add gzip support --- container/nginx/nginx.conf | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/container/nginx/nginx.conf b/container/nginx/nginx.conf index 86cb817c..98ddf0a4 100644 --- a/container/nginx/nginx.conf +++ b/container/nginx/nginx.conf @@ -39,8 +39,19 @@ http { open_file_cache_valid 60m; open_file_cache_min_uses 1; + gzip on; + gzip_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; brotli on; - brotli_types text/html text/richtext text/plain text/css text/x-script text/x-component + brotli_types 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