I am new to Ubuntu. I need to enable brotli compression on nginx server.

I am trying to install NGINX with BROTLI from the below link. https://www.howtoforge.com/tutorial/how-to-install-nginx-with-brotli-compression-on-ubuntu-1804/

when I am trying to install build package as per the link I am getting error.

root@sachin-virtual-machine:/usr/local/src# ls
nginx-1.14.2                           nginx_1.14.2-1~bionic.dsc
nginx_1.14.2-1~bionic_amd64.buildinfo  nginx_1.14.2.orig.tar.gz
nginx_1.14.2-1~bionic_amd64.changes    nginx-dbg_1.14.2-1~bionic_amd64.deb
nginx_1.14.2-1~bionic_amd64.deb        ngx_brotli
root@sachin-virtual-machine:/usr/local/src# sudo dpkg -i *.deb
dpkg: regarding nginx_1.14.2-1~bionic_amd64.deb containing nginx:
nginx conflicts with nginx-common
nginx-common (version 1.14.0-0ubuntu1.2) is present and installed.

dpkg: error processing archive nginx_1.14.2-1~bionic_amd64.deb (--install):
conflicting packages - not installing nginx
(Reading database ... 175249 files and directories currently installed.)
Preparing to unpack nginx-dbg_1.14.2-1~bionic_amd64.deb ...
Unpacking nginx-dbg (1.14.2-1~bionic) over (1.14.2-1~bionic) ...
dpkg: dependency problems prevent configuration of nginx-dbg:
nginx-dbg depends on nginx (= 1.14.2-1~bionic); however:
Version of nginx on system is 1.14.0-0ubuntu1.2.
Version of nginx on system, provided by nginx-core:amd64, is <none>.

dpkg: error processing package nginx-dbg (--install):
dependency problems - leaving unconfigured
Errors were encountered while processing:

Please guide me with this.

  • You are trying to install a different version of nginx from the one installed on your system! – George Udosen Jan 3 '19 at 7:49
  • Are you not aware that you have nginx already installed? Remove that other installed version and then build and install from source! – George Udosen Jan 3 '19 at 7:51
  • Why are you using 'sudo' when you already seem to be root? – user535733 Jan 3 '19 at 8:42
  • @user535733 its just copy paste so forgot to remove sudo – sachin makwana Jan 3 '19 at 8:51

You already have nginx installed so you have to remove that version to be able to build and install from source.

  1. Check for the new install of nginx and remove it

    dpkg -l nginx*
    • You should see the version 1.14.2, remove it with sudo dpkg remove nginx-1.14.2, and be sure you use the right version number.
  2. Now do sudo apt update and sudo apt upgrade to make sure they are no issues.

  3. Now remove the old version sudo apt purge <nginx-1.14.0>

  4. Now build that new version and install and if any issues run sudo apt install -f
  • this worked and I was able to install the package. but now I am getting following error. root@sachin-virtual-machine:/etc/nginx# nginx -t nginx: [emerg] BIO_new_file("/etc/letsencrypt/live/nginx.hakase-labs.io/fullchain.pem") failed (SSL: error:02001002:system library:fopen:No such file or directory:fopen('/etc/letsencrypt/live/nginx.hakase-labs.io/fullchain.pem','r') error:2006D080:BIO routines:BIO_new_file:no such file) nginx: configuration file /etc/nginx/nginx.conf test failed – sachin makwana Jan 3 '19 at 9:55
  • This is a different question but do you have letsencrypt installed on nginx? – George Udosen Jan 3 '19 at 10:40
  • No it wasnt'. For the localhost I needed to generate and configure own-signed privatekey and certificate. I did it and website is working fine in local environment. – sachin makwana Jan 7 '19 at 6:58

If you are already running NGINX and would like to add Brotli support, you may do so by building and installing a dynamic module. There are many steps to follow on this. To automate, here is the bash script I used in building mine:

# https://www.majlovesreg.one/tag/code/
# https://www.majlovesreg.one/adding-brotli-to-a-built-nginx-instance

# For custom NGINX version, use:
# ngver=1.14.2
# For passing via the command line, use:
# ngver=$1
# For automated detection of installed NGINX, use:
ngver=$(nginx -v 2>&1 | grep -oP '(?<=/).*')

builddir=$(mktemp -d)

# Install needed development packages if not yet installed in the system
# sudo apt -y install git libpcre3 libpcre3-dev zlib1g zlib1g-dev openssl libssl-dev

# Build in tmp directory
cd ${builddir}

# Download and unpack NGINX
wget https://nginx.org/download/nginx-${ngver}.tar.gz && { tar zxf nginx-${ngver}.tar.gz && rm nginx-${ngver}.tar.gz; } || { echo '!! download failed, exiting...'; exit 1; }

# Download, initialize, and make Brotli for NGINX
git clone https://github.com/google/ngx_brotli.git
cd ngx_brotli && git submodule update --init && cd ../nginx-${ngver}
nice -n 19 ionice -c 3 ./configure --with-compat --add-dynamic-module=../ngx_brotli || { echo '!! configure failed, exiting...'; exit 2; }
nice -n 19 ionice -c 3 make modules || { echo '!! make failed, exiting...'; exit 3; }

# Replace brotli in modules directory, i.e. /usr/share/nginx/modules/
[ -f ${moddir}/ngx_http_brotli_filter_module.so ] && sudo mv ${moddir}/ngx_http_brotli_filter_module.so ${moddir}/ngx_http_brotli_filter_module.so.old
[ -f ${moddir}/ngx_http_brotli_static_module.so ] && sudo mv ${moddir}/ngx_http_brotli_static_module.so ${moddir}/ngx_http_brotli_static_module.so.old
sudo cp objs/*.so ${moddir}/
sudo chmod 644 ${moddir}/ngx_http_brotli_filter_module.so
sudo chmod 644 ${moddir}/ngx_http_brotli_static_module.so
cd ${builddir}

# If new module works well, clean up build files
sudo nginx -t && { sudo rm -r ${builddir}/ngx_brotli; rm -r ${builddir}/nginx-${ngver}; } || { echo '!! nginx conf failed, exiting...'; exit 4; }

# Restart NGINX
systemctl is-active nginx && sudo systemctl restart nginx || sudo systemctl start nginx
systemctl --no-pager status nginx
echo 'Build and install of ngx_brotli sucessful!'

Thereafter, you will need to load the dynamic modules by adding these in nginx.conf:

load_module modules/ngx_http_brotli_filter_module.so;
load_module modules/ngx_http_brotli_static_module.so;

This answer was taken from this webpage: https://www.majlovesreg.one/adding-brotli-to-a-built-nginx-instance

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.