I want to add ngx_brotli module to nginx with this tutorial: Install Brotli Compression on Nginx (ngx_brotli)
I know that I need to install it from source and compile it by myself but I get stuck in the section where it says I need to run ./configure. In /etc/nginx this file does not exists. In #226 someone mentioned a script but how do I use it? I tried to run it with sh build_module.sh -s ~/temp/ngx_brotli/ which gave me this error:
build_module.sh: INPUT: Enter module nickname [brotli]: build_module.sh: 179: read: arg count
build_module.sh: INFO: Creating /tmp/build_module.sh.20912 build area
mkdir: created directory '/tmp/build_module.sh.20912/brotli'
build_module.sh: INFO: Building brotli from /tmp/build_module.sh.20912/brotli
build_module.sh: INFO: Downloading NGINX packaging tool
build_module.sh: 316: build_module.sh: hg: not found
build_module.sh: 317: cd: can't cd to pkg-oss/debian
build_module.sh: ERROR: Unable to obtain NGINX packaging tool - quitting
Isn't there a build in tool to add modules like Apache has it? If not, maybe it's worth building one?
As the error from build_module.sh suggests, you'd need mercurial package installed first.
Thank you and sorry I'm not familiar with build tools.
Now I'm getting a new error:
root@ee60c43e78d0:/usr/share/tmp# sh build_module.sh --skip-depends -v 1.15.12 /usr/share/ngx_brotli
DISCLAIMER DISCLAIMER DISCLAIMER DISCLAIMER DISCLAIMER DISCLAIMER DISCLAIMER
This script is provided as a demonstration of how to use the NGINX pkg-oss
tooling to compile and package a dynamic module for NGINX and NGINX Plus.
It will produce an installable package with the correct dependency on the
NGINX version used for the build so that upgrades will not lead to mismatch
between NGINX and the module. When using this script please bear in mind:
- It will not work for every module, check for module prerequisites.
- The installable packages are not intended for redistribution.
- Seamless upgrades with dependency matching require a yum/apt repository.
build_module.sh: 104: [: 1,15,12: unexpected operator
build_module.sh: INPUT: Enter module nickname [brotli]: build_module.sh: 179: read: arg count
build_module.sh: INFO: Creating /tmp/build_module.sh.23099 build area
mkdir: created directory '/tmp/build_module.sh.23099/brotli'
build_module.sh: INFO: Building brotli from /tmp/build_module.sh.23099/brotli
build_module.sh: INFO: Downloading NGINX packaging tool
destination directory: pkg-oss
adding changesets
adding manifests
adding file changes
added 299 changesets with 974 changes to 160 files
updating to branch default
75 files updated, 0 files merged, 0 files removed, 0 files unresolved
build_module.sh: INFO: Archiving module source for 1.15.12
/tmp/build_module.sh.23099/pkg-oss/debian
build_module.sh: INFO: Creating changelog
build_module.sh: INFO: Creating module Makefile
build_module.sh: INFO: Building
--2019-05-28 14:21:14-- http://nginx.org/download/nginx-1.15.12.tar.gz
Resolving nginx.org (nginx.org)... 62.210.92.35, 95.211.80.227, 2001:1af8:4060:a004:21::e3
Connecting to nginx.org (nginx.org)|62.210.92.35|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1032347 (1008K) [application/octet-stream]
Saving to: 'nginx-1.15.12.tar.gz'
nginx-1.15.12.tar.gz 100%[==================================================================>] 1008K 3.34MB/s in 0.3s
2019-05-28 14:21:14 (3.34 MB/s) - 'nginx-1.15.12.tar.gz' saved [1032347/1032347]
/root/debuild is already exists and going to be removed.
Press Enter to continue or Ctrl+C to exit
Build environment has been created in: /root/debuild
Please do the following in order to get available build targets:
cd /root/debuild/nginx-1.15.12/debian
make
===> Creating rules-module-brotli
===> Building nginx-module-brotli package
/bin/bash: debuild: command not found
real 0.00
user 0.00
sys 0.00
Makefile:303: recipe for target 'module-brotli' failed
make: *** [module-brotli] Error 127
build_module.sh: ERROR: Build failed
Could that be because the package is incompatible? "It will not work for every module, check for module prerequisites." Where can I find these prerequisites?
The module prerequisites should be documented in the module you're trying to build. This particular error comes from the need of development packages you chose to skip with "--skip-depends". You should not do that.
Ah okay I understand. I just added it because I dont have sudo I'm already the root and the scripts quits if nosudo is found.
Okay I removed sudo from the script:
vim ./build_module.sh
:%s/sudo//g
:152,157 s/.*?//g
It has finished building:
E: nginx-module-brotli source: source-contains-waf-binary debian/extra/brotli-1.15.12/deps/brotli/research/esaxx/waf
Finished running lintian.
real 48.50
user 53.05
sys 4.43
build_module.sh: INFO: Module binaries created
/root/debuild/nginx-1.15.12/debian/debuild-module-brotli/nginx-1.15.12/debian/build-nginx/objs/ngx_http_brotli_filter_module.so
/root/debuild/nginx-1.15.12/debian/debuild-module-brotli/nginx-1.15.12/debian/build-nginx/objs/ngx_http_brotli_static_module.so
/root/debuild/nginx-1.15.12/debian/debuild-module-brotli/nginx-1.15.12/debian/build-nginx-debug/objs/ngx_http_brotli_static_module-debug.so
/root/debuild/nginx-1.15.12/debian/debuild-module-brotli/nginx-1.15.12/debian/build-nginx-debug/objs/ngx_http_brotli_filter_module-debug.so
/root/debuild/nginx-1.15.12/debian/debuild-module-brotli/nginx-1.15.12/debian/nginx-module-brotli/usr/lib/nginx/modules/ngx_http_brotli_filter_module.so
/root/debuild/nginx-1.15.12/debian/debuild-module-brotli/nginx-1.15.12/debian/nginx-module-brotli/usr/lib/nginx/modules/ngx_http_brotli_static_module.so
/root/debuild/nginx-1.15.12/debian/debuild-module-brotli/nginx-1.15.12/debian/nginx-module-brotli/usr/lib/nginx/modules/ngx_http_brotli_static_module-debug.so
/root/debuild/nginx-1.15.12/debian/debuild-module-brotli/nginx-1.15.12/debian/nginx-module-brotli/usr/lib/nginx/modules/ngx_http_brotli_filter_module-debug.so
build_module.sh: INFO: Module packages created
/root/debuild/nginx-1.15.12/debian/debuild-module-brotli/nginx-module-brotli-dbg_1.15.12-1~stretch_amd64.deb
/root/debuild/nginx-1.15.12/debian/debuild-module-brotli/nginx-module-brotli_1.15.12-1~stretch_amd64.deb
build_module.sh: INFO: Removing /tmp/build_module.sh.23762
What to do next? I see that it has created some .so files. Do I need to copy them to the nginx modules dir (/usr/lib/nginx/modules) now?
The best way is just to do dpkg -i /root/debuild/nginx-1.15.12/debian/debuild-module-brotli/nginx-module-brotli_1.15.12-1~stretch_amd64.deb, which will install a package containing the modules you've just built. Then you need to enable them in the nginx.conf with the load_module directive.
Great! So now I have the modules in /usr/lib/nginx/modules/ and in nginx.conf:
load_module modules/ngx_http_brotli_static_module.so;
load_module modules/ngx_http_brotli_filter_module.so;
...
then I had run service nginx restart
but when I run nginx -V I cannot see the module loaded.
I#m so thankful you take the time to help me with that!
nginx -V wont show if the image is loaded or not. If you added a load_module directive, it will be loaded on nginx startup.
Yeah restart the container worked! Thank you very much!
For all that what to do this automatically on build time (e.g. in CI). I have created this Gist: https://gist.github.com/muuvmuuv/f1a0e7b6a6a02c2253dc92350eab7607
Hi. I've added a way to make it easier to add modules on top of the official image, please check https://github.com/nginxinc/docker-nginx/tree/master/modules for more information.
Most helpful comment
Hi. I've added a way to make it easier to add modules on top of the official image, please check https://github.com/nginxinc/docker-nginx/tree/master/modules for more information.