Compile and Install Nginx with PageSpeed Module on Debian 8
This guide explains how to manually compile and install the Nginx mainline version directly from the official Nginx sources, integrating the PageSpeed module. This module boosts website performance using various filters that optimize HTML, images, CSS, and JavaScript.
Prerequisites
- A server instance running Debian 8.
- An active sudo user account.
Manual Installation Process
System Update
Begin by updating the system packages.
sudo apt-get update
sudo apt-get dist-upgrade
Install Required Dependencies
Install the necessary software packages for compiling Nginx and PageSpeed.
sudo apt install build-essential ca-certificates zlib1g-dev libpcre3 libpcre3-dev tar unzip libssl-dev
Download and Extract ngx_pagespeed
Set a variable for the latest PageSpeed module version.
NPS_VER=1.13.35.2
Proceed to download and unpack the ngx_pagespeed source code.
cd /opt
wget https://github.com/pagespeed/ngx_pagespeed/archive/v${NPS_VER}-beta.zip
unzip v${NPS_VER}-beta.zip
rm v${NPS_VER}-beta.zip
cd ngx_pagespeed-${NPS_VER}-beta
psol_url=https://dl.google.com/dl/page-speed/psol/${NPS_VERSION}.tar.gz
[ -e scripts/format_binary_url.sh ] && psol_url=$(scripts/format_binary_url.sh PSOL_BINARY_URL)
wget ${psol_url}
tar -xzvf $(basename ${psol_url})
rm ${NPS_VER}-x64.tar.gz
Compiling and Installing Nginx
Define Nginx Version
Set a variable for the current Nginx version.
NGINX_VER=1.9.9
Alternatively, fetch it dynamically from the official Nginx changelog.
NGINX_VER=$(curl -s http://nginx.org/en/CHANGES | awk 'NR==2' | awk '{print $4}')
Download and Prepare Nginx Source
Download and extract the Nginx source files.
cd /opt
wget -qO- http://nginx.org/download/nginx-${NGINX_VER}.tar.gz | tar zxf -
Configure Nginx with PageSpeed Module
Configure Nginx with multiple modules, including ngx_pagespeed, and define build paths.
cd nginx-${NGINX_VER}
./configure \
--prefix=/etc/nginx \
--sbin-path=/usr/sbin/nginx \
--conf-path=/etc/nginx/nginx.conf \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--pid-path=/var/run/nginx.pid \
--lock-path=/var/run/nginx.lock \
--http-client-body-temp-path=/var/cache/nginx/client_temp \
--http-proxy-temp-path=/var/cache/nginx/proxy_temp \
--http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp \
--user=nginx \
--group=nginx \
--without-http_ssi_module \
--without-http_scgi_module \
--without-http_uwsgi_module \
--without-http_geo_module \
--without-http_map_module \
--without-http_split_clients_module \
--without-http_memcached_module \
--without-http_empty_gif_module \
--without-http_browser_module \
--with-threads \
--with-file-aio \
--with-http_ssl_module \
--with-http_v2_module \
--with-ipv6 \
--with-http_mp4_module \
--with-http_auth_request_module \
--with-http_slice_module \
--add-module=/opt/ngx_pagespeed-release-${NPS_VER}-beta
Compile and Install Nginx
Compile the Nginx source code by executing the following command.
make -j $(nproc)
Proceed with the installation of Nginx.
make install
To confirm that the ngx_pagespeed module has been successfully added to your Nginx installation, run the following command.
/usr/local/nginx/sbin/nginx -V
Automatic Installation
You can use an automation script that simplifies the installation process, including the addition of the PageSpeed module.
Download the Script
Retrieve the script using wget.
wget --no-check-certificate https://raw.githubusercontent.com/Qoraiche/nginx-including-pagespeed/master/nginx-autoinstall.sh -O nginx-autoinstall.sh
Make the Script Executable
Set the appropriate permissions for the script.
chmod +x nginx-autoinstall.sh
Execute the Script
Run the script to complete the automated installation.
./nginx-autoinstall.sh
At this point, the installation of the Nginx PageSpeed module is successfully completed.
Conclusion
By compiling Nginx manually and integrating the PageSpeed module, you gain full control over your server’s performance optimization. Whether you choose the manual method or the automated script, both approaches ensure a powerful and efficient Nginx installation. Your server is now ready to deliver faster content and an improved user experience, thanks to the advanced capabilities of the PageSpeed module.