Installing Nginx 1.7.9 with Google Pagespeed on Ubuntu 14.04 (Trusty)


Basically we're going to rebuild .deb packages, adding the Pagespeed module. So first we're adding the repo and preparing some dependencies:

add-apt-repository -s -y ppa:nginx/development
apt-get update
apt-get -y install devscripts
apt-get -y build-dep nginx=1.7.9

 

We're building the packages using an unprivileged user:

adduser bob −−shell /bin/bash \
--disabled-password --gecos bob
sudo su - bob

 

Get the NGINX sources:

mkdir -p ~/build/nginx
cd ~/build/nginx
NGINX_VERSION=1.7.9
apt-get -y source nginx=${NGINX_VERSION}

 

Get Pagespeed:

cd nginx-${NGINX_VERSION}/debian/modules
PAGESPEED_VERSION=1.9.32.3
wget https://github.com/pagespeed/ngx_pagespeed/archive/release-${PAGESPEED_VERSION}-beta.zip
unzip release-${PAGESPEED_VERSION}-beta.zip
rm -f release-${PAGESPEED_VERSION}-beta.zip
cd ngx_pagespeed-release-${PAGESPEED_VERSION}-beta/
wget https://dl.google.com/dl/page-speed/psol/${PAGESPEED_VERSION}.tar.gz
tar --no-same-owner -xzvf ${PAGESPEED_VERSION}.tar.gz
rm -f ${PAGESPEED_VERSION}.tar.gz

 

Fix configure script parameters to include aio and pagespeed in full and extra package variants:

cd ../..
sed -i.bak rules \
    -e's|filter_module$|filter_module --with-file-aio --add-module=$(MODULESDIR)/ngx_pagespeed-release-'${PAGESPEED_VERSION}'-beta|g'

 

Build the packages:

cd ..
debuild -i -us -uc -b -j8

 

You should end up with a bunch of .deb files in the current directory, such as nginx_1.7.8-0ubuntu1_all.deb, nginx-common_1.7.8-0ubuntu1_all.deb, etc.

To install the just built packages we switch back to root (exit or CTRL-D):

cd ~bob/build/nginx
dpkg -i nginx_*_all.deb nginx-common_*_all.deb nginx-doc_*_all.deb nginx-extras_*_amd64.deb

 

# Put the packages on hold to prevent unwanted upgrades

apt-mark hold nginx nginx-common nginx-doc nginx-extras

Add this to /etc/nginx/nginx.conf within the server section:

pagespeed on;
pagespeed ForceCaching on;
pagespeed FileCachePath /var/cache/pagespeed;

Create the cache folder and fix permissions:

mkdir -p /var/cache/pagespeed/
chown www-data:www-data /var/cache/pagespeed/

Restart nginx:

service nginx restart