Debian Tutorials

Debian Tutorials

Step by step tutorials showing you how to install and configure various applications and services on Debian based Linux distros.

June 2024


How to compile and install Nginx from source with PageSpeed module (ngx_pagespeed)

Ástþór IPÁstþór IP

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.

In this tutorial you’ll be installing Nginx 1.2. If you want to install the latest stable version of Nginx (1.6), read this instead: How to compile and install latest version of Nginx (1.6) from source with PageSpeed module (ngx_pagespeed)

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. Download Nginx source

cd /usr/src
apt-get source nginx

3. Install Nginx dependencies

apt-get build-dep nginx

4. Clone the PageSpeed git repository

git clone

5. Download and extract PSOL (PageSpeed Optimization Libraries)

cd ngx_pagespeed
tar zxvf

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

cd ../nginx-1.2.1

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

Add this line to the configuration file:

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

right before this line (in 4 places):


So that it looks like this:

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

8. Compile and create a deb package

dpkg-buildpackage -b

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

cd .. && dpkg -i nginx-common_1.2.1-2.2+wheezy3_all.deb nginx-full_1.2.1-2.2+wheezy3_amd64.deb

10. Create PageSpeed cache folder

mkdir /var/ngx_pagespeed_cache
chown www-data.www-data /var/ngx_pagespeed_cache

11. 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;

12. Restart Nginx

/etc/init.d/nginx restart

13. Check if PageSpeed is enabled

wget -O - -o /dev/null --save-headers

Replace with the hostname where you enabled pagespeed

The output should be similar to this:

HTTP/1.1 200 OK
Server: nginx/1.2.1
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
<title>Welcome to nginx!</title>
<body bgcolor="white" text="black">
<center><h1>Welcome to nginx!</h1></center>

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

14. Configure PageSpeed to fit your needs.

A list of available PageSpeed filters is available here:

Comments 2
  • veryhappy
    Posted on

    veryhappy veryhappy


    Debian package returns error when i install nginx*.deb.
    But your method works well. Thank you. Best regards.

  • Dmitry
    Posted on

    Dmitry Dmitry


    Thanx a lot! You’re great! ++