PageSpeed module is an open source, Apache-backed, and created by Google to help make web pages load faster by rewriting them to improve latency and decrease bandwidth. The PageSpeed module was created a long time ago and you probably won’t see it installed on too many web pages online today. But the concept behind it is still relevant. The primary goal behind the PageSpeed project was to optimize websites automatically, thus creating a better web experience on any device for users. If you’re running a website today and you want to give your users a better experience by optimizing your web pages, then the PageSpeed module should be a great place to start. I use it on this site and it’s performing great for my audience.
For more about the PageSpeed module, please check its website here. To get started with installing and configuring the PageSpeed module on Ubuntu with Nginx support, follow the steps below:

Install required packages

These packages are required to compile and build PageSpeed modules in Ubuntu. Run the commands below to install the packages below: After installing the packages above, continue below.

Install Nginx HTTP Server

Now that the packages above are installed, run the commands below to install the Nginx HTTP server in Ubuntu. Installing Nginx in Ubuntu is pretty straightforward. Nginx stable packages are available in Ubuntu default repositories. Simply run the commands below to install Nginx. For some reason, the Ubuntu-installed Nginx didn’t play well when I built PageSpeed modules. In that case, upgrade to the version from the Nginx official repository. Run the commands below to install the supported package. Then create the repository file in Ubuntu. and add the repository key by running the commands below: After that, upgrade by running the commands below: After installing Nginx, you’ll also want to get the version installed. You’ll need this version number to build the correct PageSpeed packages for Nginx. To find the Nginx version number, run the commands below: That will display similar lines as shown below: You’ll also want to know what modules and arguments are currently enabled and built with Nginx. We want to use the identical configuration when we’re recompiling Nginx with PageSpeed support. To find Nginx current install modules and arguments, run the commands below: That should display a similar line as below: Copy the entire line above and store it somewhere you can easily get to. We’ll use the line above below when compiling the PageSpeed module in Nginx.

Install PageSpeed module

Now that you have all the info you need, run the commands below to start compiling PageSpeed with Nginx. Replace the Nginx version number with the corresponding number currently installed on your system. When you run the command from your home directory, it will download PageSpeed packages inside your home folder. For this tutorial, the packages were downloaded in my /home/richard folder called incubator-pagespeed-ngx-latest-stable. You’ll need the path above when building Nginx to add PageSpeed module. During the build, you’ll be prompted to configure additional arguments for Nginx. Remember the PageSpeed folder created in your home directory? Include the folder in the build process. So it will look like this: Now, when prompted during the build, combine both the path above and Nginx original module and arguments output as shown above. The entire line should look like this: When prompted again, choose Y for yes. With for the build to complete. After the build is complete, the PageSpeed module should be included with Nginx. You can test by running the commands below: It should now output a line with your home directory pointing to the PageSpeed folder. Next, enable PageSpeed modules and create a symbolic link for Nginx modules. Finally, add this initial PageSpeed block to the Nginx server block of the website you wish to improve. In every server block where PageSpeed is enabled add: Save the exit from the file and reload Nginx Test PageSpeed settings. You should see an output similar to the one below That should do it. More PageSpeed configurations are available on its website. Visit the site to find more configuration options. PageSpeed Filters (modpagespeed.com) Conclusion: This post showed you how to install the PageSpeed module on Ubuntu with the Nginx HTTP server. If you find any error above, please use the comment form below to report.