How to Install Nginx with Google Page Speed

Hello

Its been a long time since I last updated my blog as I was busy with so many other projects, Today I am going to show an easy way to install Nginx with Google Page speed.

I have only tested this with Ubuntu 12.04 Precise, So here it is

apt-get install python-software-properties
apt-get install software-properties-common
**OUTDATED** apt-add-repository ppa:sandyd/nginx-current-pagespeed
apt-add-repository ppa:adegtyarev/nginx-pagespeed
apt-get update
apt-get install nginx

You now have Nginx with Google Page Speed.

Test page speed by simply adding the following line

pagespeed on;
pagespeed FileCachePath /var/ngx_pagespeed_cache;

Below is my Nginx configuration


server {
#port to listen on
listen 80;

# server name
server_name www.sohaib.com;

# root location
root /var/www/sohaib/public_html;

# access log
access_log /var/log/nginx/sohaib.com.access.log main;

# PageSpeed
pagespeed on;

# let’s speed up PageSpeed by storing it in the super duper fast memcached
pagespeed MemcachedThreads 1;
pagespeed MemcachedServers “localhost:11211”;

# show half the users an optimized site, half the regular site
pagespeed RunExperiment on;
pagespeed AnalyticsID UA-XXXXXXXXXX-1;
pagespeed ExperimentVariable 1;
pagespeed ExperimentSpec “id=1;percent=50;level=CoreFilters;enabled=collapse_whitespace,remove_comments;”;
pagespeed ExperimentSpec “id=2;percent=50”;

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

# needs to exist and be writable by nginx
pagespeed FileCachePath /var/ngx_pagespeed_cache;

# This is a temporary workaround that ensures requests for pagespeed
# optimized resources go to the pagespeed handler.
location ~ “.pagespeed.([a-z].)?[a-z]{2}.[^.]{10}.[^.]+” { }
location ~ “^/ngx_pagespeed_static/” { }
location ~ “^/ngx_pagespeed_beacon$” { }

}

Few More Tips for Page Speed which might help optimize your site

# disable CoreFilters
pagespeed RewriteLevel PassThrough;

# enable collapse whitespace filter
pagespeed EnableFilters collapse_whitespace;

# enable JavaScript library offload
pagespeed EnableFilters canonicalize_javascript_libraries;

# combine multiple CSS files into one
pagespeed EnableFilters combine_css;

# combine multiple JavaScript files into one
pagespeed EnableFilters combine_javascript;

# remove tags with default attributes
pagespeed EnableFilters elide_attributes;

# improve resource cacheability
pagespeed EnableFilters extend_cache;

# flatten CSS files by replacing @import with the imported file
pagespeed EnableFilters flatten_css_imports;
pagespeed CssFlattenMaxBytes 5120;

# defer the loading of images which are not visible to the client
pagespeed EnableFilters lazyload_images;

# enable JavaScript minification
pagespeed EnableFilters rewrite_javascript;

# enable image optimization
pagespeed EnableFilters rewrite_images;

# pre-solve DNS lookup
pagespeed EnableFilters insert_dns_prefetch;

# rewrite CSS to load page-rendering CSS rules first.
pagespeed EnableFilters prioritize_critical_css;
}

# enable CoreFilters
pagespeed RewriteLevel CoreFilters;

# disable particular filter(s) in CoreFilters
pagespeed DisableFilters rewrite_images;

# enable additional filter(s) selectively
pagespeed EnableFilters collapse_whitespace;
pagespeed EnableFilters lazyload_images;
pagespeed EnableFilters insert_dns_prefetch;
}

Leave a Reply

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