How to install ngx_pagespeed with Nginx on Ubuntu

Google now ranks a site on the basis of its loading speed also.Speeding up a website is a very difficult task for web masters.But smart people will take advantage of ngx_pagespeed which can optimize your website at server level.Since we are installing module on Nginx so there is way no simple way to install it after installation like in Apache.

So we need to install ngx_pagespeed at the time of installation.With ngx_pagespeed you can minify javascipt,css also you can compress images.

Install LEMP Stack on Ubuntu

  • Install WordPress on Nginx

Installing necessary packages

Pagespeed module require some package which you should install to make pagespeed run properly,issue the following command in terminal.

sudo apt-get install build-essential zlib1g-dev libpcre3 libpcre3-dev unzip

Download ngx_pagespeed

After installing necessary packages its time to download ngx_pagespeed.Run the command mention below.

unzip release-${NPS_VERSION}
cd ngx_pagespeed-release-${NPS_VERSION}-beta/
tar -xzvf ${NPS_VERSION}.tar.gz

You need to run the above commands one by one.In this we will be installing ngx_pagespeed version

Download and build Nginx

Now we have downloaded ngx_pagespeed we need to configure nginx so that it will use ngx_pagespeed module.Issue the command in terminal.

tar -xvzf nginx-${NGINX_VERSION}.tar.gz
cd nginx-${NGINX_VERSION}/
./configure –add-module=$HOME/ngx_pagespeed-release-${NPS_VERSION}-beta
sudo make install

This will install Nginx will ngx_pagespeed module.After that you need to start web server.Issue the following command to start or stop the web server.You can also make a script to start and stop web server.

To start web server

sudo /usr/local/nginx/sbin/nginx

To stop web server

sudo /usr/local/nginx/sbin/nginx -s stop

Configuring Nginx with ngx_pagespeed

We have build Nginx with pagespeed support.Now we need to configure pagespeed.You can to edit the nginx.conf file issue the commands.

sudo nano /usr/local/nginx/conf/nginx.conf

Then you need to the following line the every server block where you want to enable pagespeed.

pagespeed on;

# Needs to exist and be writable by nginx. Use tmpfs for best performance.
pagespeed FileCachePath /var/ngx_pagespeed_cache;

# 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 ~ “^/pagespeed_static/” { }
location ~ “^/ngx_pagespeed_beacon$” { }

The default filters are good enough for a web server but you can also add more filters.For more details about filters you refer to the Google PageSpeed Filter Docs.
Also Read about: Top CDN Providers to Speed Up Your Website

Leave Comment

Your email address will not be published. Required fields are marked *