How To Install Nginx With Ngx_Pagespeed Module on Ubuntu 16.04 LTS

r00t June 1, 2017

Install Nginx With Ngx_Pagespeed Module on Ubuntu 16.04 LTS

In this tutorial we will show you how to install and configure nginx with ngx_pagespeed module on Ubuntu 16.04 LTS. For those of you who didn’t know, 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. For the installation, we will need to compile nginx from souce with the PageSpeed module, as Nginx doesn’t support Dynamic module loading (DSO), unless you want to build your own rpm or deb files.

This article assumes you have at least basic knowledge of linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo’ to the commands to get root privileges. I will show you through the step by step installation nginx with pagespeed module on a Ubuntu 16.04 (Xenial Xerus) server.

Install Nginx With Ngx_Pagespeed Module on Ubuntu 16.04 LTS

Step 1. First make sure that all your system packages are up-to-date by running these following apt-get commands in the terminal.

Step 2. Add the Nginx repository.

Run the commands below in terminal to compiling the latest Nginx mainline version:

Create a new repository and edit the sources.list file:

Add the following two lines at the end of this file:

Step 3. Download Nginx from source package.

Create a new directory for the nginx source files and download the nginx sources using apt command:

Check out the downloaded files:

Step 4. Download ngx_pagespeed source package.

To compile Nginx with ngx_pagespeed module, we also need ngx_pagespeed source package. Go to Github ngx_pagespeed download page:

Unzip into the current directory:

Next, we also need to download the psol library. (PageSpeed Optimization Library) and extract it:

Step 5. Configure Nginx to build with Pagespeed.

First, edit Nginx compilation rule file:

Add the new line under ‘COMMON_CONFIGURE_ARGS’:

Step 6. Start the Compilation Nginx Ubuntu package.

Go to the nginx source directory and build nginx from source with the dpkg-buildpackage command:

When it’s done, there will be 7 deb files in ~/nginx/ directory. We only need to install the nginx_1.11.1-1~xenial_amd64.deb or nginx_1.11.1-1~xenial_i386.deb package, depending on your OS architecture. The others are Nginx dynamic module package and a debug package:

Now let’s start Nginx:

Step 7. Configure ngx_pagespeed Module in Nginx.

Now edit Nginx server block config file:

Add the following pagespeed directives in server section:

Finally, restart Nginx service:

Step 8. Check if PageSpeed is Working.

Go to your website. Refresh a few times then check your page source. Hit Ctrl+F key and search pagespeed. You will see that many of your website resource has been processed by pagespeed or you can issue the following command:

Congratulation’s! You have successfully installed nginx pagespeed. Thanks for using this tutorial for installing nginx with ngx_pagespeed module on Ubuntu 16.04 LTS  (Xenial Xerus) system. For additional help or useful information, we recommend you to check the official Nginx web site.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get a best deal!



Share on Google+0Share on Facebook0Tweet about this on TwitterShare on Tumblr0Share on StumbleUpon1Share on Reddit1Pin on Pinterest1
The Tags:

Leave a Comment