Skip to content

Commit

Permalink
feat: Add nginx njs dynamic module in base image
Browse files Browse the repository at this point in the history
Signed-off-by: Anurag Rajawat <[email protected]>
  • Loading branch information
anurag-rajawat committed Nov 11, 2024
1 parent 79c684f commit dce4341
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 1 deletion.
4 changes: 4 additions & 0 deletions docs/user-guide/nginx-configuration/configmap.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ The following table shows a configuration option's name, type, and the default v
| [use-geoip2](#use-geoip2) | bool | "false" | |
| [geoip2-autoreload-in-minutes](#geoip2-autoreload-in-minutes) | int | "0" | |
| [enable-brotli](#enable-brotli) | bool | "false" | |
| [enable-njs](#enable-njs) | bool | "false" | |
| [brotli-level](#brotli-level) | int | 4 | |
| [brotli-min-length](#brotli-min-length) | int | 20 | |
| [brotli-types](#brotli-types) | string | "application/xml+rss application/atom+xml application/javascript application/x-javascript application/json application/rss+xml application/vnd.ms-fontobject application/x-font-ttf application/x-web-app-manifest+json application/xhtml+xml application/xml font/opentype image/svg+xml image/x-icon text/css text/javascript text/plain text/x-component" | |
Expand Down Expand Up @@ -733,6 +734,9 @@ _**default:**_ false

> __Note:__ Brotli does not works in Safari < 11. For more information see [https://caniuse.com/#feat=brotli](https://caniuse.com/#feat=brotli)
## enable-njs
Enables or disables [njs](https://nginx.org/en/docs/njs/) module. _**default: false**_

## brotli-level

Sets the Brotli Compression Level that will be used. _**default:**_ 4
Expand Down
9 changes: 8 additions & 1 deletion images/nginx/rootfs/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ export OPENTELEMETRY_CPP_VERSION="v1.11.0"
# Check on https://github.com/open-telemetry/opentelemetry-proto
export OPENTELEMETRY_PROTO_VERSION="v1.1.0"

# http://hg.nginx.org/njs
export NGINX_NJS_VERSION="0.8.4"

export BUILD_PATH=/tmp/build

ARCH=$(uname -m)
Expand Down Expand Up @@ -276,6 +279,9 @@ get_src efb767487ea3f6031577b9b224467ddbda2ad51a41c5867a47582d4ad85d609e \
get_src d74f86ada2329016068bc5a243268f1f555edd620b6a7d6ce89295e7d6cf18da \
"https://github.com/microsoft/mimalloc/archive/${MIMALOC_VERSION}.tar.gz" "mimalloc"

get_src 8191bff8491af9169a92e30e383ef8614717b0c6d40913d83b95051031e92321 \
"http://hg.nginx.org/njs/archive/${NGINX_NJS_VERSION}.tar.gz" "njs"

# improve compilation times
CORES=$(($(grep -c ^processor /proc/cpuinfo) - 1))

Expand Down Expand Up @@ -481,7 +487,8 @@ WITH_MODULES=" \
--add-dynamic-module=$BUILD_PATH/nginx-http-auth-digest \
--add-dynamic-module=$BUILD_PATH/ModSecurity-nginx \
--add-dynamic-module=$BUILD_PATH/ngx_http_geoip2_module \
--add-dynamic-module=$BUILD_PATH/ngx_brotli"
--add-dynamic-module=$BUILD_PATH/ngx_brotli \
--add-dynamic-module=$BUILD_PATH/njs/nginx"

./configure \
--prefix=/usr/local/nginx \
Expand Down
4 changes: 4 additions & 0 deletions internal/ingress/controller/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,9 @@ type Configuration struct {
// MIME Types that will be compressed on-the-fly using Brotli module
BrotliTypes string `json:"brotli-types,omitempty"`

// Enables NGINX JS
EnableNJS bool `json:"enable-njs,omitempty"`

// Enables or disables the HTTP/2 support in secure connections
// http://nginx.org/en/docs/http/ngx_http_v2_module.html
// Default: true
Expand Down Expand Up @@ -767,6 +770,7 @@ func NewDefault() Configuration {
BrotliLevel: 4,
BrotliMinLength: 20,
BrotliTypes: brotliTypes,
EnableNJS: false,
ClientHeaderBufferSize: "1k",
ClientHeaderTimeout: 60,
ClientBodyBufferSize: "8k",
Expand Down
4 changes: 4 additions & 0 deletions rootfs/etc/nginx/template/nginx.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ load_module /etc/nginx/modules/ngx_http_modsecurity_module.so;
load_module /etc/nginx/modules/otel_ngx_module.so;
{{ end }}

{{ if $cfg.EnableNJS }}
load_module /etc/nginx/modules/ngx_http_js_module.so;
{{ end }}

daemon off;

worker_processes {{ $cfg.WorkerProcesses }};
Expand Down

0 comments on commit dce4341

Please sign in to comment.