This guide will demonstrate how to install Nginx with Google PageSpeed Module on Ubuntu 20.04 LTS. Google PageSpeed is an open-source A...
This guide will demonstrate how to install Nginx with Google PageSpeed Module on Ubuntu 20.04 LTS. Google PageSpeed is an open-source Apache module developed by Google to assist Make the Web Faster by rewriting web pages to minimise latency and bandwidth. The loading speed of website pages influences both the user experience and the site's position in search engine results. A Google PageSpeed module is available to assess and speed up the loading of material.
This post assumes you have a basic understanding of Linux, know how to use the shell, and, most importantly, host your site on your own VPS. The installation is straightforward and assumes you are running in the root account; if you are not, you may need to add'sudo' to the instructions to gain root access. I'll walk you through the process of installing Nginx with Google PageSpeed Module on Ubuntu 20.04. (Focal Fossa).
Install Nginx With Google PageSpeed Module on Ubuntu 20.04 LTS Focal Fossa
1. First, make sure that all your system packages are up-to-date by running the following apt commands in the terminal.
sudo apt update sudo apt upgrade sudo apt install curl libssl-dev
2. Installing Nginx on Ubuntu 20.04.
sudo apt install nginx
Once Nginx installed you can verify the version:
nginx -V
Output:
nginx version: nginx/1.18.0 (Ubuntu) built with OpenSSL 1.1.1f 20 May 2021 TLS SNI support enabled configure arguments: ...
3. Installing the Google PageSpeed module.
Now we execute the following command to install all required dependencies as well as the PageSpeed module:
bash <(curl -f -L -sS https://ngxpagespeed.com/install) \ --nginx-version 1.18.0
All questions should be answered favourably during installation. Following the next request, you can specify which further modules should be included in the assembly:
About to build nginx. Do you have any additional ./configure arguments you would like to set? For example, if you would like to build nginx with https support give --with-http_ssl_module If you don't have any, just press enter. >
The default set of parameters is shown below:
--prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-proxy-temp-path=/var/lib/nginx/proxy --http-scgi-temp-path=/var/lib/nginx/scgi --http-uwsgi-temp-path=/var/lib/nginx/uwsgi --with-compat --with-stream=dynamic --with-stream_ssl_module --with-mail=dynamic --with-mail_ssl_module --with-http_ssl_module --with-http_v2_module
Once the installation is done, create the following symbolic link:
ln -s /usr/lib/nginx/modules /etc/nginx/modules
To verify that the installation:
nginx -V
Output:
... configure arguments: --add-module=/root/incubator-pagespeed-ngx-latest-stable ...
4. Setup Google PageSpeed Module.
Now we edit the Nginx main configuration file and define the enabling Google PageSpeed module path:
nano /etc/nginx/sites-available/default
Add the following file:
server {
…
pagespeed on;
pagespeed FileCachePath "/var/cache/ngx_pagespeed/";
pagespeed RewriteLevel OptimizeForBandwidth;
location ~ ".pagespeed.([a-z].)?[a-z]{2}.[^.]{10}.[^.]+" {
add_header "" "";
}
location ~ "^/pagespeed_static/" { }
location ~ "^/ngx_pagespeed_beacon$" { }
…
}
To apply the changes reload the systemd daemon:
nginx -t
Next, we create a new index.html file the webroot directory:
echo "Hallo, Linux!" > /var/www/html/index.html
Finally, restart the Nginx service to apply the changes:
sudo systemctl restart nginx
5. Test the Google PageSpeed Module.
The easiest way to make sure that the Google PageSpeed module is working is to access our website using curl:
curl -I -p http://your-server-IP or your-domain-name
Output:
HTTP/1.1 200 OK Server: nginx/1.18.0 Content-Type: text/html Connection: keep-alive Date: Wed, 21 May 2021 16:36:08 GMT X-Page-Speed: 1.13.35.2-0 Cache-Control: max-age=0, no-cache
Congratulations! You have completed the installation of Nginx with Google PageSpeed. Thank you for following this article on how to install Nginx with Google PageSpeed Module on an Ubuntu 20.04 LTS Focal Fossa system.
COMMENTS