Debian Tutorials

Debian Tutorials


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

March 2024
M T W T F S S
 123
45678910
11121314151617
18192021222324
25262728293031

Categories


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 https://github.com/pagespeed/ngx_pagespeed.git

5. 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

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):

$(CONFIGURE_OPTS) >$@

So that it looks like this:

...
--add-module=/usr/src/ngx_pagespeed \
$(CONFIGURE_OPTS) >$@
...

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 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.2.1
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
 
<html>
<head>
<title>Welcome to nginx!</title>
</head>
<body bgcolor="white" text="black">
<center><h1>Welcome to nginx!</h1></center>
</body>
</html>

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: http://ngxpagespeed.com/ngx_pagespeed_example/

Comments 2
  • veryhappy
    Posted on

    veryhappy veryhappy

    Author

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


  • Dmitry
    Posted on

    Dmitry Dmitry

    Author

    Thanx a lot! You’re great! ++