# How to Install Nginx with Google Page Speed

URL: https://sohaib.com/blog/how-to-install-nginx-with-google-page-speed
Author: Sohaib Khan
Published: Aug 20, 2014
Updated: Sep 8, 2026
Category: Web Servers & DevOps

> 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…

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

```bash
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

```nginx
pagespeed on;
pagespeed FileCachePath /var/ngx_pagespeed_cache;
```

Below is my Nginx configuration

```nginx

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

```bash
# 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; }

```bash
 # 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; }
