How to use the PageSpeed ​​module (ngx_pagespeed) to compile and install the latest version of Nginx (1.6) from source code

PageSpeed ​​(ngx_pagespeed) is an Nginx module created by Google that helps to increase network speed by rewriting web pages to reduce latency and bandwidth.

Debian Wheezy comes with version 1.2, which is outdated. Here’s how to install the latest stable version of Nginx using the PageSpeed ​​module.

This tutorial has been tested on Debian 7.x (lighter), 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 Nginx apt repository to apt source

echo "deb wheezy nginx
deb-src wheezy nginx" >> /etc/apt/sources.list

3. Download and install Nginx public 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://

8. Download and decompress PSOL (PageSpeed ​​Optimization Library)

cd ngx_pagespeed
tar zxvf

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

cd ../nginx-1.6.2

10. Modify Nginx production rules (pico debian / rules)

Add this line to the configuration file:


Just after this line (in 2 places):


This looks like this:


11. Compile and create a deb package

dpkg-buildpackage -b

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

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 /etc/nginx/nginx.conf or http {} in the 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

Replace with a pagespeed-enabled hostname

The output should be similar to the following:

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
Cache-Control: max-age=0, no-cache

If you see the X-Page-Speed ​​property in the title, PageSpeed ​​is enabled.

17. Configure PageSpeed ​​to meet your needs.

A list of available PageSpeed ​​filters is available here:

Source link