in Web, Wheezy

How to compile and install latest version of Nginx (1.6) from source with PageSpeed module (ngx_pagespeed)

PageSpeed (ngx_pagespeed) is a Nginx module created by Google to help Make the Web Faster by rewriting web pages to reduce latency and bandwidth.

The version included with Debian Wheezy is 1.2 which is getting pretty old. Here’s how to install the latest stable version of Nginx with the PageSpeed module.

This tutorial is tested on Debian 7.x (wheezy) but may work with other versions.

1. Install required packages

apt-get install dpkg-dev build-essential zlib1g-dev libpcre3 libpcre3-dev git

2. Add the Nginx apt repository to apt sources

echo "deb http://nginx.org/packages/debian/ wheezy nginx
deb-src http://nginx.org/packages/debian/ wheezy nginx" >> /etc/apt/sources.list

3. Download and install the Nginx public key

wget http://nginx.org/packages/keys/nginx_signing.key
cat nginx_signing.key | apt-key add -

4. Update apt

apt-get update

5. Download Nginx source

cd /usr/src
apt-get source nginx

6. Install Nginx dependencies

apt-get build-dep nginx

7. Clone the PageSpeed git repository

git clone git://github.com/pagespeed/ngx_pagespeed.git

8. Download and extract PSOL (PageSpeed Optimization Libraries)

cd ngx_pagespeed
wget https://dl.google.com/dl/page-speed/psol/1.9.32.2.tar.gz
tar zxvf 1.9.32.2.tar.gz

9. Enter the Nginx source directory (The version number may be different on your system)

cd ../nginx-1.6.2

10. Modify the make rules for Nginx (pico debian/rules)

Add this line to the configuration file:

--add-module=/usr/src/ngx_pagespeed \

right after this line (in 2 places):

$(WITH_SPDY) \

So that it looks like this:

...
$(WITH_SPDY) \
--add-module=/usr/src/ngx_pagespeed \
...

11. Compile and create a deb package

dpkg-buildpackage -b

12. Install Nginx (The version number may be different on your system)

cd .. && dpkg -i nginx_1.6.2-1~wheezy_amd64.deb

13. Create PageSpeed cache folder

mkdir /var/ngx_pagespeed_cache
chown nginx.nginx /var/ngx_pagespeed_cache

14. Enable PageSpeed by adding these lines to http {} in /etc/nginx/nginx.conf or a virtual host

pagespeed on;
pagespeed FileCachePath /var/ngx_pagespeed_cache;

15. Restart Nginx

/etc/init.d/nginx restart

16. Check if PageSpeed is enabled

wget -O - -o /dev/null --save-headers yourdomain.com

Replace yourdomain.com with the hostname where you enabled pagespeed

The output should be similar to this:

HTTP/1.1 200 OK
Server: nginx/1.6.2
Content-Type: text/html
Transfer-Encoding: chunked
Connection: keep-alive
Date: Sat, 29 Nov 2014 22:57:28 GMT
X-Page-Speed: 1.9.32.2-4321
Cache-Control: max-age=0, no-cache
...

If you see a X-Page-Speed property in the header, PageSpeed is enabled.

17. Configure PageSpeed to fit your needs.

A list of available PageSpeed filters is available here: http://ngxpagespeed.com/ngx_pagespeed_example/

Write a Comment

Comment

  1. hello, I have a problem when following the above guidelines, Can you help to solve it
    Thx

    root@xxxx:/usr/src/nginx-1.6.2/debian# dpkg-buildpackage -b
    tail: cannot open `debian/changelog’ for reading: No such file or directory
    dpkg-buildpackage: error: tail of debian/changelog gave error exit status 1

  2. hi wike,
    so you ran ‘dpkg-buildpackage -b’ command and your prompt was reading root@xxxx:/usr/src/nginx-1.6.2/debian#
    try using this command
    root@xxxx:/usr/src/nginx-1.6.2/debian# cd .. && dpkg-buildpackage -b
    your prompt will then be
    root@xxxx:/usr/src/nginx-1.6.2#
    then run this command
    root@xxxx:/usr/src/nginx-1.6.2# dpkg -i nginx_1.6.2-1~wheezy_amd64.deb
    this should do it