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 :

wget http://nginx.org/keys/nginx_signing.key
sudo apt-key add nginx_signing.key

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

deb http://nginx.org/packages/debian/ codename nginx (for 12.04 codename is squeeze)
deb-src http://nginx.org/packages/debian/ 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 :


wget https://github.com/pagespeed/ngx_pagespeed/archive/release-1.5.27.3-beta.zip
unzip release-1.5.27.3-beta.zip
cd ngx_pagespeed-release-1.5.27.3-beta
wget https://dl.google.com/dl/page-speed/psol/1.5.27.3.tar.gz
tar xzvf 1.5.27.3.tar.gz
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 :

--add-module=../ngx_pagespeed-release-1.5.27.3-beta

it will look like this :

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


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 :

X-Page-Speed: 1.5.27.3-xxxx

Any feedback on this instructions is welcome

For More detailed information please read :

https://github.com/pagespeed/ngx_pagespeed
http://nginx.org/en/linux_packages.html#stable

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

Posted in Web Performance Tagged with: , , , ,
%d bloggers like this: