Using Pagespeed

Note: This feature is depreciated with EasyEngine v3.6.0.

Note: Test your site properly before using this in production.

Adding Nginx repo

If you are EasyEngine user then you can skip this step

For Ubuntu 12.04/14.04:

add-apt-repository -y ppa:rtcamp/nginx
apt-get update

For Debian 6/7:

echo "deb http://packages.dotdeb.org $(lsb_release -sc) all" > /etc/apt/sources.list.d/dotdeb-$(lsb_release -sc).list
apt-get update

Installation of Nginx Pagespeed

For Ubuntu 12.04/14.04:

apt-get install nginx-custom

Note: If you are using EasyEngine then this step is not required

For Debian 6/7:

apt-get install nginx-extras

This will install nginx-extras on your server, by removing nginx-full.

Creating Pagespeed global configuration

Create new pagespeed global configuration file

vim /etc/nginx/conf.d/pagespeed.conf

and paste following code into it

# Turning the module on and off
pagespeed on;

ADVERTISEMENT
# Configuring PageSpeed Filters pagespeed RewriteLevel PassThrough; # Needs to exist and be writable by nginx. Use tmpfs for best performance. pagespeed MemcachedServers "127.0.0.1:11211"; pagespeed FileCachePath /var/ngx_pagespeed_cache; # PageSpeed Admin pagespeed StatisticsPath /ngx_pagespeed_statistics; pagespeed GlobalStatisticsPath /ngx_pagespeed_global_statistics; pagespeed MessagesPath /ngx_pagespeed_message; pagespeed ConsolePath /pagespeed_console; pagespeed AdminPath /pagespeed_admin; pagespeed GlobalAdminPath /pagespeed_global_admin; # PageSpeed Cache Purge pagespeed EnableCachePurge on; pagespeed PurgeMethod PURGE;

Creating site specific Pagespeed configuration

Create new site specific configuration file

vim /etc/nginx/common/pagespeed.conf

Paste following code into it

# PageSpeed Admin
location /ngx_pagespeed_statistics { include common/acl.conf; }
location /ngx_pagespeed_global_statistics { include common/acl.conf; }
location /ngx_pagespeed_message { include common/acl.conf; }
location /pagespeed_console { include common/acl.conf; }
location ~ ^/pagespeed_admin { include common/acl.conf; }
location ~ ^/pagespeed_global_admin { include common/acl.conf; }

ADVERTISEMENT
# 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$" { }

 

Enable Pagespeed for site

Open site Nginx configuration:

vim /etc/nginx/sites-available/example.com

add following line at in the configurations:

include common/pagespeed.conf;

and restart Nginx

nginx -t && service nginx restart

Enable/Disable PageSpeed Filters

 

Please paste following filter inside /etc/nginx/sites-available/example.com

 

# HTTPS Support
# pagespeed FetchHttps enable;

# PageSpeed Filters
# CSS Minification
# pagespeed EnableFilters combine_css,rewrite_css;

# JS Minification
# pagespeed EnableFilters combine_javascript,rewrite_javascript;

ADVERTISEMENT
# Images Optimization #pagespeed EnableFilters lazyload_images; #pagespeed EnableFilters rewrite_images; #pagespeed EnableFilters convert_jpeg_to_progressive,convert_png_to_jpeg,convert_jpeg_to_webp,convert_to_webp_lossless; # Remove comments from HTML #pagespeed EnableFilters remove_comments; # Remove WHITESPACE from HTML #pagespeed EnableFilters collapse_whitespace; # CDN Support #pagespeed MapRewriteDomain cdn.example.com www.example.com;

 

By default we commented all filters. You can uncomment filters that you need for your site.

Also you can add various filters from here to this file: https://developers.google.com/speed/pagespeed/module/filters

Test your site

You can test site by pointing browser to example.com, and seeing its html code.

View Pagespeed statistics

You can view Pagespeed statics by poinitng your browser to http://example.com/ngx_pagespeed_statistics

Disable Pagespeed temporary

You can disable pagespeed temporary by using this url: http://example.com/?PageSpeed=off

Purge Pagespeed Cache

You can purge specific file cache by hitting following url http://exmple.com/pagespeed_admin/cache?purge=/path/file.ext