20.8 C

Google PageSpeed Module on Apache and NGINX

In the case of web servers, speed is a really important matter as thousands of visitors visiting the site(s) on the server every single time. For improving the performance of the server, Google’s PageSpeed module is very useful. In fact, this module can even speed the site up to 10 times! Today, let’s have a look on installing the module on Linux server. Learn how to manage your GNU Linux server with Netdata.

Instructions for Apache

Apache is, by far, the most popular choice for as a server on most Linux installations. That’s why Google also prefers this route of enjoying their product. If you’re using Debian/Ubuntu server, CentOS, RHEL (Red Hat Enterprise Linux) or Suse Enterprise Linux, follow the instructions for enabling the module.

Note that Google currently doesn’t have support for Linux server distros that don’t use DEB or RPM packages. That’s why for using on other platforms, the NGINX server is recommended.

  • Ubuntu server

- Advertisement -

Run the following command for installing Google PageSpeed on Ubuntu server.

# For installing Stable release of PageSpeed
wget https://dl-ssl.google.com/dl/linux/direct/mod-pagespeed-stable_current_amd64.deb
wget https://dl-ssl.google.com/dl/linux/direct/mod-pagespeed-stable_current_i386.deb

sudo dpkg -i mod-pagespeed-stable_current_*.deb
sudo apt install -f

# For installing Beta release of PageSpeed
wget https://dl-ssl.google.com/dl/linux/direct/mod-pagespeed-beta_current_amd64.deb
wget https://dl-ssl.google.com/dl/linux/direct/mod-pagespeed-beta_current_i386.deb

sudo dpkg -i mod-pagespeed-beta_current_*.deb
sudo apt install -f
  • RHEL/CentOS

Thankfully, these server distros have the support for the RPM package. You can simply install it without following any complicated process.

# Beta release
wget https://dl-ssl.google.com/dl/linux/direct/mod-pagespeed-beta_current_x86_64.rpm
wget https://dl-ssl.google.com/dl/linux/direct/mod-pagespeed-beta_current_i386.rpm

# Stable release
wget https://dl-ssl.google.com/dl/linux/direct/mod-pagespeed-stable_current_x86_64.rpm
wget https://dl-ssl.google.com/dl/linux/direct/mod-pagespeed-stable_current_i386.rpm

# Install RPM package
sudo rpm -U mod-pagespeed-*.rpm

NGINX guide

If your server OS is different than that, you have to go in this route for enjoying Google PageSpeed. However, unlike Apache, Google doesn’t provide so easy-to-install method. Instead, it has to be built and configured by hand.

There’s a script available for the task. Run the command for executing the script and setting everything up. The script requires curl, so make sure that you have curl installed for your system.

bash <(curl -f -L -sS https://ngxpagespeed.com/install) \
--nginx-version latest

Configuring PageSpeed

It’s time to configure PageSpeed module. For Apache server, there’s no configuration required. However, on NGINX, you have to configure the system. For enabling PageSpeed module with NGINX, edit the “nginx.conf” file. Run the following commands:

su -
sudo -s

nano /etc/nginx/nginx.conf

Now, add the following lines at the last of the file.

pagespeed on;
# Needs to exist and be writable by nginx. Use tmpfs for best performance.
pagespeed FileCachePath /var/ngx_pagespeed_cache;
# 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$" { }

Press “Ctrl + O” and “Ctrl + X” for saving and exiting the editor.

Disable PageSpeed

PageSpeed is superb for having a better performance on your web server. However, if you’re in need of disabling the extension, it’s super easy.

  • Apache
# Ubuntu/Debian
sudo apt-get remove mod-pagespeed
sudo apt remove mod-pagespeed-beta

sudo yum remove mod-pagespeed
sudo yum remove mod-pagespeed-beta

In the case of NGINX, go through the same process of editing the “nginx.conf” and turn off PageSpeed.

su -
sudo -s

nano /etc/nginx/nginx.conf

Enjoy the blazing performance of your server!

- Advertisement -
Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
"The best Linux newsletter on the web"


Please enter your comment!
Please enter your name here

Latest article