Introduction
Mod_pagespeed is an open source Apache module that is used to automatically optimize web pages. It makes the web faster by rewriting web pages to reduce latency and bandwidth. Mod_pagespeed also provides many optimization filters that are used to optimize various files such as css
, html
, png
, and jpg
.
In this tutorial, I will explain how to install and configure the Mod_pagespeed module with Apache on Ubuntu 16.04.
Prerequisites
- A newly deployed Vultr Ubuntu 16.04 server instance with Apache installed.
- A non-root user with sudo privileges setup on your server.
- A static IP address 192.168.15.110 configure on your system.
Step 1: Update the system
Before starting, update your system to the latest stable version by running the following command:
sudo apt-get update -y
sudo apt-get upgrade -y
sudo reboot
Step 2: Install Mod_pagespeed
You can download the latest stable version of Mod_pagespeed module for Apache from it’s official website.
Otherwise you can download it with the following command:
wget https://dl-ssl.google.com/dl/linux/direct/mod-pagespeed-stable_current_amd64.deb
Once download is complete, install it by running the following command:
sudo dpkg -i mod-pagespeed-stable_current_amd64.deb
sudo apt-get install -f
Once installation is finished, you will need to restart Apache service to load the module:
sudo systemctl restart apache2
You can verify the Mod_pagespeed module by running the following curl
command:
curl -D- localhost
If everything was successful, you will see the following output:
HTTP/1.1 200 OK
Date: Mon, 28 Nov 2016 15:28:51 GMT
Server: Apache/2.4.7 (Ubuntu)
Accept-Ranges: bytes
Vary: Accept-Encoding
X-Mod-Pagespeed: 1.11.33.2-0
Cache-Control: max-age=0, no-cache
Content-Length: 10724
Content-Type: text/html; charset=UTF-8
Step 3: Configure the Mod_pagespeed module
You can configure Mod_pagespeed module different ways. Either you can use the default pagespeed.conf
file to configure it for the whole server, or you can put your all of its settings in your virtual host directive.
Let’s start by editing the default pagespeed.conf
file:
sudo nano /etc/apache2/mods-available/pagespeed.conf
To disable Mod_pagespeed module change the line from on
to off
.
ModPagespeed off
Mod_pagespeed uses different types of levels that makes configuration simple such as PassThrough
, CoreFilters
, and OptimizeForBandwidth
.
The default setting is:
ModPagespeedRewriteLevel CoreFilters
To disable CoreFilters
change the lines to:
ModPagespeedRewriteLevel PassThrough
If you want to enable additional filters specify:
ModPagespeedEnableFilters filter1 filter2
To disable filter specify:
ModPagespeedDisableFilters filter1 filter2
Step 4: Access Mod_pagespeed web interface
Mod_pagespeed module provides a web based interface to view server state. You will need to add your remote machine’s IP address in pagespeed.conf
file to access it from a remote machine.
sudo nano /etc/apache2/mods-available/pagespeed.conf
Change the file as shown below:
<Location /pagespeed_admin>
Order allow,deny
Allow from localhost
Allow from 127.0.0.1
Allow from remote-ip-address
SetHandler pagespeed_admin
</Location>
<Location /pagespeed_global_admin>
Order allow,deny
Allow from localhost
Allow from 127.0.0.1
Allow from remote-ip-address
SetHandler pagespeed_global_admin
</Location>
Save the file and restart the Apache service.
sudo systemctl restart apache2
Next, open your web browser and type the URL http://192.168.15.110/pagespeed_admin
to access the Mod_pagespeed web interface.
Mod_pagespeed is now installed and configured on your server.
Want to contribute?
You could earn up to $300 by adding new articles
Suggest an update
Request an article