Compile and Install Nginx With the PageSpeed Module on Debian 8
In this article, we will see how to compile and install Nginx mainline from the official sources of Nginx with the PageSpeed module, which allows you to accelerate your website through several filters. These filters act on HTML, images, CSS or Javascript.
##Prerequisites
- A newly deployed Vultr instance running Debian 8.
- A sudo user.
##Manual installation
Update the system.
sudo apt-get update
sudo apt-get dist-upgrade
Install dependencies.
sudo apt install build-essential ca-certificates zlib1g-dev libpcre3 libpcre3-dev tar unzip libssl-dev
Define a variable with the latest version of the PageSpeed module.
NPS_VER=1.13.35.2
Next, we need to download and extract the source code for ngx-pagespeed
.
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
Compilation and installation of Nginx
Define a variable with the latest version of Nginx.
NGINX_VER=1.9.9
Or define it via the Nginx website.
NGINX_VER=$(curl -s http://nginx.org/en/CHANGES | awk 'NR==2' | awk '{print $4}')
Next, we need to download the source code for Nginx.
cd /opt
wget -qO- http://nginx.org/download/nginx-${NGINX_VER}.tar.gz | tar zxf -
Configure the parameters and modules. The Nginx PageSpeed module is included.
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.
make -j $(nproc)
Install.
make install
You can verify that the ngx_pagespeed
module has been added to Nginx installation as follows.
/usr/local/nginx/sbin/nginx -V
##Automatic installation
Get the automation script, which allows you to install several modules, including the PageSpeed module.
wget --no-check-certificate https://raw.githubusercontent.com/Qoraiche/nginx-including-pagespeed/master/nginx-autoinstall.sh -O nginx-autoinstall.sh
Make it executable.
chmod +x nginx-autoinstall.sh
Execute it.
./nginx-autoinstall.sh
Your Nginx PageSpeed module installation is now complete.