Configure Pagespeed with Apache in Ubuntu Web Server
What is Pagespeed and how to use
One of the more recently popular modules for Apache is mod_pagespeed. It is an output filter for Apache 2.2+ that can be configured through a variety of options through configuration files or a .htaccess file. It makes a layer between your website and the user who browse your websites. An “output filter” is a something that transforms the data before it’s sent to the client.
Installation is very simple. It’ll vary depending on the operating system you use. Ubuntu have packages you can download and install Other Linux distributions can download the source and build from that.
If you’re on a 64-bit version (likely)…
If you’re on a 32-bit version (less likely)…
sudo dpkg -i mod-pagespeed-*.deb apt-get -f install
Remove the downloaded package
The module enables itself automatically when installed. However, you must restart Apache for it to start working.
service apache2 restart
You should now have a working version of mod_pagespeed up and running on your VPS. You can check this by looking at your page’s response headers. There should be a value for “X-Mod-Pagespeed” with the version number you installed.
Pagespeed module automatic install with apache.Depending on the Apache version you’re running, you’ll get a different version of the module installed and enabled. If you’re running Apache 2.2, mod_pagespeed.so will be installed; Apache 2.4 users will use mod_pagespeed_24.so.
Additionally, configuration files have been added to your Apache installation. The primary configuration file is pagespped.conf This file is located at:
Configure Pagespeed with Apache in Ubuntu
The defaults for mod_pagespeed are good, but you’ll often find that you can get better performance with a few additional tweaks to your site. Every site will get different results with different settings and it’s best to play around and find the settings that work best for you and your site.
There are a few different ways mod_pagespeed can be configured. You can use the pagespeed.conf file described above to configure it for the whole server. Or, if you’d rather, you can put your configuration settings in the VirtualHost directive for an Apache virtual host/website. Finally, you have the option of specifying directives in a .htaccess file, such as what most sites do for mod_rewrite.
To start editing the main configuration file, use the following command:
In general, the settings in pagespeed.conf are pretty well documented inside the file. There is also a great list of filter examples available from http://www.modpagespeed.com. Here are a few common settings you might want to play with to optimize for your site’s performance.
Turn mod_pagespeed On/Off
First off, you can turn the module on or off with the ModPagespeed setting.
You can specify different “levels” of settings to simplify any configuration. The default is CoreFilters It contains a set of filters the Google team believes is safe for use. The filters are the individual actions that are applied to a file. In general, you won’t need to change this value. It’s easier to use this default and then enable or disable filters using the ModPagespeedEnableFilters and ModPagespeedDisableFilters directives.
The default setting:
To disable CoreFilters use this setting:
Note: You’ll have to explicitly enable any filters you want to turn on using the PassThrough setting.
Using the default “CoreFilters” rewrite level includes a number of filters by default. As of the time of this writing, it includes:?
New filters will be added in the future. By using CoreFilters, you’ll automatically have these filters enabled if they become part of the default set whenever you update mod_pagespeed. Using PassThrough will require you to explicitly enable the new filters.
You can have multiple ModPagespeedEnableFilters directives throughout your configuration files. So, if you want to enable a filter per site, you could enable it in the virtual host configuration file or in the .htaccess file instead of in the main pagespeed.conf file.
The following example disables the “Convert JPEG to Progressive” filter even though it’s part of the CoreFilters set:
Specify Which URLs are Rewritten
This would disable rewriting of any files that match the wildcard pattern specified (jquery UI in this case).
You can also turn off the rewriting of all files by default and only enable files you want to rewrite manually. You can do this with the following settings:
ModPagespeedDisallow "*" ModPagespeedAllow "http://*linuxtweaks.in/*/styles/*.css"
Don’t forget if you’re using the pagespeed.conf or VirtualHost files to alter the settings, you’ll have to restart Apache for the settings to take effect. You can do this with the following commands:
service apache2 restart