Budiono Darmawan

an eCommerce Wizard

Build Nginx with Pagespeed From Ubuntu 14.04


    1. Fresh Ubuntu 14.04
    2. Sudo access

First, always update and upgrade:

sudo apt-get update -y&& sudo apt-get upgrade -y

Add needed software

sudo apt-get install software-properties-common curl unzip -y

Add Nginx stable repo

sudo add-apt-repository -y ppa:nginx/stable


Usually latest Nginx can be installed with below command

sudo apt-get update
sudo apt-get install -y nginx

However, we need to recompile nginx. If you already have nginx installed, you can remove it using

sudo apt-get remove nginx

Next, we need to download pagespeed module. At this time of writing, latest pagespeed version is You can check it here.

sudo mkdir /opt/pagespeed
cd /opt/pagespeed
NPS_VERSION= #latest version when time of writing is change if needed
sudo wget https://github.com/pagespeed/ngx_pagespeed/archive/release-${NPS_VERSION}-beta.zip
sudo unzip release-${NPS_VERSION}-beta.zip
cd ngx_pagespeed-release-${NPS_VERSION}-beta/
sudo wget https://dl.google.com/dl/page-speed/psol/${NPS_VERSION}.tar.gz
sudo tar -xzvf ${NPS_VERSION}.tar.gz # extracts to psol/
# Gives us directory /opt/pagespeed/ngx_pagespeed-release-

Then we need to edit the PPA’s sources file and ensure the deb-src directive is not commented out.

nano /etc/apt/sources.list.d/nginx-stable-trusty.list

If displayed like below,

deb http://ppa.launchpad.net/nginx/stable/ubuntu trusty main
# deb-src http://ppa.launchpad.net/nginx/stable/ubuntu trusty main

Uncomment the 2nd line become

deb http://ppa.launchpad.net/nginx/stable/ubuntu trusty main
deb-src http://ppa.launchpad.net/nginx/stable/ubuntu trusty main

Save and quit by press ctrl+x, Y, Enter

Then we need to update

sudo apt-get update

After that we can get Nginx’s source package

sudo apt-get install -y dpkg-dev
sudo mkdir /opt/rebuildnginx
cd /opt/rebuildnginx
sudo apt-get source nginx
sudo apt-get build-dep nginx -y

As of the time of this writing, the latest stable Nginx installed on Ubuntu Trusty is 1.10.1.

ls -lah /opt/rebuildnginx

We need to add Google Pagespeed module in /opt/rebuildnginx/nginx-1.6.2/debian/rules

sudo nano /opt/rebuildnginx/nginx-1.10.1/debian/rules

Add below line in the full_configure_flags section


It will become

Save and quit by press ctrl+x, Y, Enter

Then we can start build Nginx

cd /opt/rebuildnginx/nginx-1.10.1/
sudo dpkg-buildpackage -b

If you experience error
Please check again your rules file, sometime, you give space by mistake.

After finished, go to /opt/rebuildnginx

cd /opt/rebuildnginx

sudo dpkg --install nginx-common_1.10.1-0+trusty0_all.deb #skip this command if you installed a Nginx before
sudo dpkg --install nginx-full_1.10.1-0+trusty0_amd64.deb

Now we have nginx with Pagespeed Module. You can check it by

nginx -V


Next, we need to enable Pagespeed module. Backup nginx.conf then edit nginx configuration

sudo cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.bak
sudo nano /etc/nginx/nginx.conf

Add below lines in site nginx site configuration server block

pagespeed on;

# Needs to exist and be writable by nginx. Use tmpfs for best performance.
pagespeed FileCachePath /var/ngx_pagespeed_cache;

# Ensure requests for pagespeed optimized resources go to the pagespeed handler
# and no extraneous headers get set.
location ~ “\.pagespeed\.([a-z]\.)?[a-z]{2}\.[^.]{10}\.[^.]+” {
add_header “” “”;
location ~ “^/pagespeed_static/” { }
location ~ “^/ngx_pagespeed_beacon$” { }

Then create directory for Pagespeed

sudo mkdir -p /var/ngx_pagespeed_cache



Your email address will not be published. Required fields are marked *