Google’s mod_pagespeed is a great piece of software for speeding up web pages. Unfortunately however it doesn’t work for everything. Some of the most common filters can in fact cause your code not to validate at a minimum or, as a worst case, break your site altogether. For many of us who run our own servers installing mod_pagespeed may benefit one site while breaking another. Or, as in my case, different filters may be necessary depending on the site. Here’s a quick tutorial to make this work using Ubuntu Server 10.04LTS with named virtual hosts.
First, log into your server via SSH or otherwise.
Next we need to download the latest mod_pagespeed package.
Note, that if you use the x86 version of Ubuntu server you’ll want to replace the above line with
Next, install the package and clean up the installation file
sudo dpkg -i mod-pagespeed.deb rm mod-pagespeed.deb
At this point mod_pagespeed will be installed, but we still need to configure it. We’ll start by editing the primary mod_pagespeed configuration file to disable the module globally.
sudo nano /etc/apache2/mods-available/pagespeed.conf
Within the file, on the 4th line it should read:
Save and exit the file.
Next, we’re going to edit the individual virtualhost we want to apply mod_pagespeed to.
Open the site you wish to edit in your favorite text editor and enter the following lines between the VirtualHost tags:
note that you may wish to change the options. Click here for a list of available mod_pagespeed filters.
Save the file and restart apache.
sudo /etc/init.d/apache2 restart
Go to the site in question and view source (you might need to clean the cache out). You should be able to see the module in action by the changes to your page source.