There is a new version of this tutorial available for Debian 11 (Bullseye).

Using ngx_pagespeed With nginx On Debian Wheezy

Google has just released PageSpeed Beta for nginx, the nginx equivalent of mod_pagespeed for Apache. This module applies web performance best practices to pages, and associated assets (CSS, JavaScript, images) and therefore speeds up your web site and reduces load times. This tutorial explains how to use PageSpeed with nginx on Debian Wheezy.

I do not issue any guarantee that this will work for you!


1 Building nginx With PageSpeed

nginx does not support dynamic loading of modules, therefore we must rebuild it with PageSpeed support. We will build nginx as a .deb package so that we can replace our existing nginx installation with it (or easily install it on other systems).

Create the build directory first:

cd /usr/src
mkdir pagespeed && cd pagespeed

Make sure you have deb and deb-src lines for Wheezy in /etc/apt/sources.list:

vi /etc/apt/sources.list
deb wheezy main
deb-src wheezy main

Update your packages list and install some prerequisites:

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

Download the nginx sources and the build dependencies:

apt-get source nginx
apt-get build-dep nginx

Let's check our nginx version:

ls -l

[email protected]:/usr/src/pagespeed# ls -l
total 2044
drwxr-xr-x 10 root root    4096 Apr 29 13:03 nginx-1.2.1
-rw-r--r--  1 root root 1360507 Aug  5  2012 nginx_1.2.1-2.2.debian.tar.gz
-rw-r--r--  1 root root    2740 Aug  5  2012 nginx_1.2.1-2.2.dsc
-rw-r--r--  1 root root  718161 Jun 27  2012 nginx_1.2.1.orig.tar.gz
[email protected]:/usr/src/pagespeed#

Our nginx version is 1.2.1. Let's go to the debian/modules directory of the downloaded nginx sources...

cd /usr/src/pagespeed/nginx-1.2.1/debian/modules

... and download the PageSpeed sources:

git clone

Let's edit the debian/rules file:

vi /usr/src/pagespeed/nginx-1.2.1/debian/rules

In that file you will find four config.status sections (config.status.full, config.status.light, config.status.extras, config.status.naxsi). Add the line --add-module=$(MODULESDIR)/ngx_pagespeed \ to each of them, right before the $(CONFIGURE_OPTS) >[email protected] line, e.g. as follows:

config.status.full: config.env.full config.sub config.guess
        cd $(BUILDDIR_full) && CFLAGS="$(CFLAGS)" CORE_LINK="$(LDFLAGS)" ./configure  \
            --prefix=/etc/nginx \
            --conf-path=/etc/nginx/nginx.conf \
            --error-log-path=/var/log/nginx/error.log \
            --http-client-body-temp-path=/var/lib/nginx/body \
            --http-fastcgi-temp-path=/var/lib/nginx/fastcgi \
            --http-log-path=/var/log/nginx/access.log \
            --http-proxy-temp-path=/var/lib/nginx/proxy \
            --http-scgi-temp-path=/var/lib/nginx/scgi \
            --http-uwsgi-temp-path=/var/lib/nginx/uwsgi \
            --lock-path=/var/lock/nginx.lock \
            --pid-path=/var/run/ \
            --with-pcre-jit \
            --with-debug \
            --with-http_addition_module \
            --with-http_dav_module \
            --with-http_geoip_module \
            --with-http_gzip_static_module \
            --with-http_image_filter_module \
            --with-http_realip_module \
            --with-http_stub_status_module \
            --with-http_ssl_module \
            --with-http_sub_module \
            --with-http_xslt_module \
            --with-ipv6 \
            --with-sha1=/usr/include/openssl \
            --with-md5=/usr/include/openssl \
            --with-mail \
            --with-mail_ssl_module \
            --add-module=$(MODULESDIR)/nginx-auth-pam \
            --add-module=$(MODULESDIR)/nginx-echo \
            --add-module=$(MODULESDIR)/nginx-upstream-fair \
            --add-module=$(MODULESDIR)/nginx-dav-ext-module \
            --add-module=$(MODULESDIR)/ngx_pagespeed \
            $(CONFIGURE_OPTS) >[email protected]
        touch [email protected]

Now let's build our new nginx packages:

cd /usr/src/pagespeed/nginx-1.2.1/ && dpkg-buildpackage -b

Afterwards, let's take a look at the generated packages:

cd /usr/src/pagespeed
ls -l

[email protected]:/usr/src/pagespeed# ls -l
total 35464
drwxr-xr-x 10 root root    4096 Apr 29 13:12 nginx-1.2.1
-rw-r--r--  1 root root   61006 Apr 29 13:12 nginx_1.2.1-2.2_all.deb
-rw-r--r--  1 root root    5143 Apr 29 13:12 nginx_1.2.1-2.2_amd64.changes
-rw-r--r--  1 root root 1360507 Aug  5  2012 nginx_1.2.1-2.2.debian.tar.gz
-rw-r--r--  1 root root    2740 Aug  5  2012 nginx_1.2.1-2.2.dsc
-rw-r--r--  1 root root  718161 Jun 27  2012 nginx_1.2.1.orig.tar.gz
-rw-r--r--  1 root root   72632 Apr 29 13:12 nginx-common_1.2.1-2.2_all.deb
-rw-r--r--  1 root root   74042 Apr 29 13:12 nginx-doc_1.2.1-2.2_all.deb
-rw-r--r--  1 root root 4140470 Apr 29 13:12 nginx-extras_1.2.1-2.2_amd64.deb
-rw-r--r--  1 root root 6075706 Apr 29 13:12 nginx-extras-dbg_1.2.1-2.2_amd64.deb
-rw-r--r--  1 root root 3931344 Apr 29 13:12 nginx-full_1.2.1-2.2_amd64.deb
-rw-r--r--  1 root root 4609688 Apr 29 13:12 nginx-full-dbg_1.2.1-2.2_amd64.deb
-rw-r--r--  1 root root 3815222 Apr 29 13:12 nginx-light_1.2.1-2.2_amd64.deb
-rw-r--r--  1 root root 3546806 Apr 29 13:12 nginx-light-dbg_1.2.1-2.2_amd64.deb
-rw-r--r--  1 root root 3853762 Apr 29 13:12 nginx-naxsi_1.2.1-2.2_amd64.deb
-rw-r--r--  1 root root 3673646 Apr 29 13:12 nginx-naxsi-dbg_1.2.1-2.2_amd64.deb
-rw-r--r--  1 root root  342008 Apr 29 13:12 nginx-naxsi-ui_1.2.1-2.2_all.deb
[email protected]:/usr/src/pagespeed#

We can now install nginx with PageSpeed support as follows:

dpkg --install nginx-common_1.2.1-2.2_all.deb nginx_1.2.1-2.2_all.deb nginx-full_1.2.1-2.2_amd64.deb

Let's check if the PageSpeed module was built successfully:

nginx -V

You should see the ngx_pagespeed module in the output:

[email protected]:/usr/src/pagespeed# nginx -V
nginx version: nginx/1.2.1
TLS SNI support enabled
configure arguments: --prefix=/etc/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-client-body-temp-path=/var/lib/nginx/body
--http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-log-path=/var/log/nginx/access.log --http-proxy-temp-path=/var/lib/nginx/proxy --http-scgi-temp-path=/var/lib/nginx/scgi
--http-uwsgi-temp-path=/var/lib/nginx/uwsgi --lock-path=/var/lock/nginx.lock --pid-path=/var/run/ --with-pcre-jit --with-debug --with-http_addition_module
--with-http_dav_module --with-http_geoip_module --with-http_gzip_static_module --with-http_image_filter_module --with-http_realip_module --with-http_stub_status_module
--with-http_ssl_module --with-http_sub_module --with-http_xslt_module --with-ipv6 --with-sha1=/usr/include/openssl --with-md5=/usr/include/openssl --with-mail --with-mail_ssl_module
--add-module=/usr/src/pagespeed/nginx-1.2.1/debian/modules/nginx-auth-pam --add-module=/usr/src/pagespeed/nginx-1.2.1/debian/modules/nginx-echo
--add-module=/usr/src/pagespeed/nginx-1.2.1/debian/modules/nginx-upstream-fair --add-module=/usr/src/pagespeed/nginx-1.2.1/debian/modules/nginx-dav-ext-module
[email protected]:/usr/src/pagespeed#


2 Configuring PageSpeed

To enable PageSpeed, open /etc/nginx/nginx.conf...

vi /etc/nginx/nginx.conf

... and add the lines pagespeed on; and pagespeed FileCachePath /var/ngx_pagespeed_cache; before any vhosts:

        pagespeed on;
        pagespeed FileCachePath /var/ngx_pagespeed_cache;

        # Virtual Host Configs

        include /etc/nginx/conf.d/*.conf;
        include /etc/nginx/sites-enabled/*;

Create the cache directory and restart nginx (please note that whenever you modify the PageSpeed configuration, no matter if in the main nginx configuration or in a vhost, you must restart nginx - a simple reload does not work):

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

/etc/init.d/nginx restart

[email protected]:~# /etc/init.d/nginx restart
Restarting nginx: Setting option from ("on")
Setting option from ("FileCachePath", "/var/ngx_pagespeed_cache")
[email protected]:~#

Let's load a page and check if PageSpeed is mentioned in the output:

curl -I -p http://localhost|grep X-Page-Speed

[email protected]:~# curl -I -p http://localhost|grep X-Page-Speed
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
[email protected]:~#

Now we can configure PageSpeed individually or each vhost, e.g. like this:

vi /etc/nginx/sites-available/
server {
  # let's speed up PageSpeed by storing it in the super duper fast memcached
  pagespeed MemcachedThreads 1;
  pagespeed MemcachedServers "localhost:11211";

  # Filter settings
  pagespeed RewriteLevel CoreFilters;
  pagespeed EnableFilters collapse_whitespace,remove_comments;

  #  Ensure requests for pagespeed optimized resources go to the pagespeed
  #  handler and no extraneous headers get set.
  location ~ "\.pagespeed\.([a-z]\.)?[a-z]{2}\.[^.]{10}\.[^.]+" {
    add_header "" "";
  location ~ "^/ngx_pagespeed_static/" {
  location ~ "^/ngx_pagespeed_beacon$" {
  location /ngx_pagespeed_statistics {
    allow; deny all;
  location /ngx_pagespeed_message {
    allow; deny all;

The important line is the pagespeed EnableFilters line which tells PageSpeed which filters it should apply. You can find a list of all filters here:

Don't forget to restart nginx afterwards:

/etc/init.d/nginx restart 

When you open a page now and take a look at the headers (e.g. with the Live HTTP headers add-on for FireFox), you should see an x-page-speed line:

You can check the HTML sources of your pages to see if the PageSpeed filters work as expected.



About The Author

Falko Timme is the owner of nginx WebhostingTimme Hosting (ultra-fast nginx web hosting). He is the lead maintainer of HowtoForge (since 2005) and one of the core developers of ISPConfig (since 2000). He has also contributed to the O'Reilly book "Linux System Administration".

Share this page:

Suggested articles

4 Comment(s)

Add comment


By: YoLaBingo

Excellent walk-through - thank you!

By: YoLaBingo

Actually, I had to deviate a little to get this working. Specifically, I had to download both the mod_PageSpeed  sources as well as PSOL sources, and grabbed release packages so they matched. Following the instructions at

So instead of 

 git clone

I did

cd ngx_pagespeed-release-
tar -xzvf # expands to psol/

and then was able to build nginx package.

By: voku1987


 PS: here you can find the google-howto ->

By: Neo2SHYAlien

Also to compile 1.7.30 beta module will be necessary to rename pagespeed folder or change the path to module in rule file.