Skip to content

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…

Sohaib Khan2 min read
How to Install Nginx with Google Page Speed — editorial illustration

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

Shell6 lines
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

Nginx2 lines
pagespeed on;
pagespeed FileCachePath /var/ngx_pagespeed_cache;

Below is my Nginx configuration

Nginx4 lines

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.(.)?{2}.[^.]{10}.[^.]+" { } location ~ "^/ngx_pagespeed_static/" { } location ~ "^/ngx_pagespeed_beacon$" { } } Few More Tips for Page Speed which might help optimize your site

Shell2 lines
# 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; }

Shell2 lines
 # 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; }

Was this worth your time?

Continue reading

Full archive

17 min read

Automating Proxmox VM Deployment

In the world of virtualization and infrastructure management, efficiency is everything. Today, I'm excited to share our latest automation script that transforms the traditionally manual process of creating virtual…

5 min read

DocFlux 2.0: A PDF Knowledge Base

In this post, I’ll walk you through the journey of building DocFlux 2.0, a robust PDF knowledge base application using Python, FastAPI, and cutting-edge NLP tools like OpenAI’s API. We’ll also cover how the frontend…