How to Build nginx 1.4.1 and ngx_pagespeed in Ubuntu/Debian

Create a directory to download necessary packages (optional) :

mkdir pagespeed; cd pagespeed

Make sure that you have latest version of nginx, I recommend using nginx repo.

To add nginx repo :

sudo apt-key add nginx_signing.key

Add this lines to /etc/apt/sources.list file:

deb codename nginx (for 12.04 codename is squeeze)
deb-src codename nginx

Download nginx sources and build packages :

sudo apt-get update
sudo apt-get install dpkg-dev
sudo apt-get source nginx

Build nginx deps :

sudo apt-get build-dep nginx

Make sure you have this ngx_pagespeed requirements :

sudo apt-get install build-essential zlib1g-dev libpcre3 libpcre3-dev

Download ngx_pagespeed git repo :

cd ngx_pagespeed-release-
tar xzvf
cd ..

Update : Before I was using git clone but is not a good idea since master brach keeps changing and can brake things.

Edit build rules for nginx 1.4.1 package :

vim nginx-1.4.1/debian/rules

and add :


it will look like this :

--with-file-aio \
--add-module=../ngx_pagespeed-release- \
<em id="__mceDel">$(WITH_SPDY) \

Build nginx 1.4.0 debian package with pagespeed module :

cd nginx-1.4.1/ && dpkg-buildpackage -b

Install new nginx deb package:

cd .. && dpkg --install nginx_1.4.1-1~squeeze_amd64.deb

Note: If you have nginx installed you will need to remove it and then reinstall the new package ( do not use –purge options otherwise you will delete all your config files)

Add this lines to /etc/nginx.conf to test if pagespeed works :

http {
pagespeed on;
pagespeed FileCachePath /var/ngx_pagespeed_cache;

Create pagespeed cache directory and change permissions :

mkdir /var/ngx_pagespeed_cache
chown -R www-data:www-data /var/ngx_pagespeed_cache

Reload nginx :

nginx -s reload

Test if pagespeed is working :

curl -I -p http://localhost:8080/index.php|grep X-Page-Speed

Note: make sure to use the correct url

you should see :


Any feedback on this instructions is welcome

For More detailed information please read :

Note :This process could be used to build basically any module for nginx that is not on the nginx-full or default dedian package