How to use the PageSpeed ​​module (ngx_pagespeed) to compile and install Nginx from source

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.

In this tutorial, you will install Nginx 1.2. If you want to install the latest stable version of Nginx (1.6), please read: How to use the PageSpeed ​​module (ngx_pagespeed) to compile and install the latest version of Nginx (1.6) from source code.

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

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 decompress PSOL (PageSpeed ​​Optimization Library)

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 on the system may be different)

cd ../nginx-1.2.1

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

Add this line to the configuration file:

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

Just before this line (in 4 places):

$(CONFIGURE_OPTS) >[email protected]

This looks like this:

...
--add-module=/usr/src/ngx_pagespeed
$(CONFIGURE_OPTS) >[email protected]
...

8. Compile and create a deb package

dpkg-buildpackage -b

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

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

The output should be similar to the following:

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
 


Welcome to nginx!


Welcome to nginx!



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

14. Configure PageSpeed ​​to meet your needs.

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

Source link

Sidebar