mod_pagespeed with Apache on Ubuntu 16.04

By | October 29, 2016


mod_pagespeed is an open source and most popular modules for Apache web server that automatically optimize Web Pages to improve better performance while serving web pages using HTTP Server. This module is created by Google to help make the web server faster by rewriting web pages to reduce latency and bandwidth and by compressing javascript and css files. It can be configured through a variety of filters that automatically optimize files like HTML, CSS, JavaScript, JPEG, PNG and other resources to speed up your website.

In this tutorial, we will learn how to install and configure Google‘s mod_pagespeed module for Apache to improve the page load times of your website.


  • Ubuntu 16.04 server with Apache installed on your system.
  • Non-root user account with sudo privilege set up on your server.

Getting Started

Let’s start making sure that your Ubuntu-16.04 server is fully up to date.

You can update your server by running the following command:

sudo apt-get update -y
sudo apt-get upgrade -y

Installing Mod_Pagespeed

Before proceeding with mod_pagespeed module, make sure that Apache installed on your system.

Now download the mod-pagespeed module for Apache2 from the official site, or download it by running the following command:


After downloading above package, you can install it using the following command:

dpkg -i mod-pagespeed-stable_current_amd64.deb
sudo apt-get install -f

Installing mod_pagespeed from binary packages will add a Google’s official repository to your system, so that you can update the module any time using Ubuntu package manager. After successful installation, you will need to restart Apache service to load module.

sudo /etc/init.d/apache2 restart

You can check mod_pagespeed module by looking at your page’s response headers by running the following command:

curl -D- localhost | less

If everything is fine, you should see the following output:

HTTP/1.1 200 OK
Date: Mon, 22 Aug 2016 18:21:57 GMT
Server: Apache/2.4.7 (Ubuntu)
Accept-Ranges: bytes
Vary: Accept-Encoding
Cache-Control: max-age=0, no-cache
Content-Length: 10724
Content-Type: text/html; charset=UTF-8

You should now have mod_pagespeed up and running on your server.

Configuring mod_pagespeed

By default, mod_pagespeed module comes with most commonly used filters. The main configuration file for mod_pagespeed is located at /etc/apache2/mods-available/pagespeed.conf. This configuration file is used for global configuration for mod_pagespeed. You can also put your site-specific PageSpeed filters in Apache VirtualHost directive.

To start editing the main configuration file, use the following command:

sudo nano /etc/apache2/mods-available/pagespeed.conf

If you want to disable mod_pagespeed module the change the line from:

ModPagespeed on


ModPagespeed off

Save the file and restart the Apache service:

sudo /etc/init.d/apache2 restart

Configuring PageSpeed Filters

Mod_Pagespeed uses three types of levels that makes configuration simple. PassThrough, CoreFilters, and OptimizeForBandwidth. The CoreFilters level enables a default set of filters that will make your website faster. The OptimizeForBandwidth level provides a stronger guarantee of safety that are not aware of PageSpeed. You can disable CoreFilters by setting the RewriteLevel to PassThrough. You can do this by editing pagespeed.conf file:

sudo nano /etc/apache2/mods-available/pagespeed.conf

Add / Edit the following line:

ModPagespeedRewriteLevel PassThrough

You can also enable and disable specific filters:

sudo nano /etc/apache2/mods-available/pagespeed.conf

To turn off specific filters in the core set, specify:

ModPagespeedDisableFilters filter1,filter2

To turn on specific filters in the core set, specify:

ModPagespeedEisableFilters filter1,filter2

Mod_Pagespeed Web Admin

Apache’s mod_pagespeed module also provide a web based admin area to view the server state. By default, it is accessible from localhost only. You will need to add your IP Address in Allow from list in the configuration file.

You can do this by editing the pagespeed.conf file:

sudo nano  /etc/apache2/mods-available/pagespeed.conf

Under the directive <location pagespeed_admin=””> and <location pagespeed_global_admin=””> add the line “allow from your-ip-address”.

<Location /pagespeed_admin>
    Order allow,deny
    Allow from localhost
    Allow from
    Allow from your-ip-address
    SetHandler pagespeed_admin

<Location /pagespeed_global_admin>
    Order allow,deny
    Allow from localhost
    Allow from
    Allow from your-ip-address
    SetHandler pagespeed_global_admin

Save the file and restart the Apache service.

sudo /etc/init.d/apache2 restart

Now access the URL http://server-ip-address/pagespeed_admin in your browser, You will see the following page:

mod_pagespeed Admin Panel

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.