Nginx is a popular web server that is known for its high performance and low resource consumption. Google PageSpeed is a performance optimization module that can be used to improve the loading speed of web pages. In this article, we will go over the steps for setting up Nginx with the Google PageSpeed module on a fresh installation of Debian 11.
Before we begin, make sure you have a user that has sudo privileges on your Debian 11 system.
Install Nginx
To start, we need to install Nginx on our system. To do this, run the following command:
sudo apt-get install -y nginx
After the installation is complete, start the Nginx service and enable it to start automatically on boot:
sudo systemctl start nginx
sudo systemctl enable nginx
To verify that Nginx is working correctly, access the URL http://your-server-ip in a web browser. You should see the default Nginx welcome page.
Install the PageSpeed module
Next, we need to install the Google PageSpeed module for Nginx. To do this, we need to first install the build-essential package, which includes the necessary tools for building and compiling software from source code. Run the following command to install it:
sudo apt-get install -y build-essential
After the installation is complete, download the latest PageSpeed module source code from the Google PageSpeed repository:
wget <https://github.com/apache/incubator-pagespeed-ngx/archive/v1.13.35.2-stable.tar.gz>
Next, extract the downloaded tarball:
tar -xzvf v1.13.35.2-stable.tar.gz
Change into the extracted directory and build the PageSpeed module:
cd incubator-pagespeed-ngx-1.13.35.2-stable/
sudo make BUILD_TYPE=Release
After the build is complete, install the PageSpeed module by running the following command:
sudo make install
This will install the PageSpeed module and its dependencies on your system.
Now that we have installed the PageSpeed module, we need to enable it in the Nginx configuration.
To do this, open the Nginx configuration file /etc/nginx/nginx.conf and add the following lines at the top of the file:
load_module /usr/lib/nginx/modules/ngx_pagespeed.so;
pagespeed on;
pagespeed FileCachePath /var/ngx_pagespeed_cache;
Save the file and exit.
Next, create the directory for the PageSpeed cache:
sudo mkdir -p /var/ngx_pagespeed_cache
Finally, restart the Nginx service to apply the changes:
sudo systemctl restart nginx
To verify that the PageSpeed module is working correctly, access the URL http://your-server-ip/pagespeed_admin in a web browser. You should see the PageSpeed Admin Console, which provides an overview of the performance improvements made by the PageSpeed module.
Configure the firewall
If you have a firewall enabled on your system, you will need to allow access to the Nginx port (80) in order to access it from a remote machine.
To do this, run the following commands to open port 80 and reload the firewall rules:
sudo ufw allow 80/tcp
sudo ufw reload
Conclusion
In this article, we went over the steps for setting up Nginx with the Google PageSpeed module on a fresh installation of Debian 11. We installed Nginx and the PageSpeed module, enabled the PageSpeed module in the Nginx configuration, and verified that it was working correctly. We also covered how to configure the firewall to allow access to Nginx.
I hope this tutorial has been helpful for you. Happy speeding up your web pages!