This brief tutorial  to set up the Google Pagespeed module on Ubuntu 20.04. 18.04 with Nginx HTTP help.

The Pagespeed module is an open supply, supported by Apache and constructed by Google to assist internet pages load sooner by rewriting them to enhance latency and cut back bandwidth.

The PageSpeed ​​module was created a very long time in the past and also you in all probability will not see it put in on a whole lot of internet pages on-line in the present day. However the idea behind it’s nonetheless related.

The first aim behind the PageSpeed ​​challenge was to mechanically optimize web sites, thus creating a greater internet expertise for customers on any system.

In case you are operating a web site in the present day and also you need to give your customers a greater expertise by optimizing your internet pages, then PageSpeed ​​module must be an excellent place to start out.

I apply it to this web site and it’s performing very properly for my viewers.

For extra details about the Pagespeed module, please verify Website here.

To get began with putting in and configuring the PageSpeed ​​module on Ubuntu with nginx help, observe the steps under:

Set up required bundle

These packages are wanted to compile and construct the Pagespeed module in Ubuntu. To put in the packages under, run the next command:

sudo apt update 
sudo apt install libssl-dev libxslt-dev libgd-dev curl nano

After putting in the above packages, proceed under.

Set up nginx http server

Now that the above packages have been put in, run the under command to put in Nginx HTTP Server in Ubuntu. Putting in Nginx in Ubuntu may be very simple. Nginx static packages can be found within the Ubuntu default repository.

To put in nginx, simply run the command under.

sudo apt install nginx

Once I constructed the Pagespeed module Ubuntu put in NGN for some purpose which didn’t work properly. In that case, improve to the model from the Nginx official repository.

Run the command under to put in the supported bundle.

sudo apt install gnupg2 ca-certificates lsb-release

Then create a repository file in Ubuntu.

echo "deb http://nginx.org/packages/ubuntu lsb_release -cs nginx" | sudo tee/etc/apt/sources.list.d/nginx.list

And add the repository key by operating the next instructions:

curl -fsSL https://nginx.org/keys/nginx_signing.key | sudo apt-key add -

After that, improve by operating the next command:

sudo apt update 
sudo apt install nginx

After putting in nginx, you’ll want to set up the model as properly. You will have this model quantity to create the right Pagespeed bundle for nginx.

To search out the nginx model quantity, run the next command:

nginx -v

It will show the identical strains as proven under:

nginx version: nginx/1.20.0

You may also need to know which modules and logic are at the moment enabled and constructed with Nginx. Once we are recompiling Nginx with PageSpeed ​​help, we need to use the identical configuration.

To search out Nginx present put in modules and logic, run the instructions under:

nginx -V

It ought to show the identical line as under:

--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/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt="-g -O2 -fdebug-prefix-map=/data/builder/debuild/nginx-1.20.0/debian/debuild-base/nginx-1.20.0=. -fstack-protector-strong -Wformat -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fPIC" --with-ld-opt="-Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now -Wl,--as-needed -pie"

Copy the complete line above and retailer it in a spot the place you possibly can attain it simply. We are going to use the road under when compiling the PageSpeed ​​module in nginx.

Set up pagespeed module

Now that you’ve all the knowledge you want, run the command under to start out compiling PageSpeed ​​with Nginx.

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

Exchange the nginx model quantity with the corresponding quantity at the moment put in in your system. Whenever you run the command from your own home listing, it can obtain the pagespeed bundle inside your own home folder.

For this tutorial, bundle my. Had been downloaded in / home / anmol A folder named incubator-pagespeed-ngx-latest-static.

/home/anmol/incubator-pagespeed-ngx-latest-stable

You will have the above path when constructing Nginx so as to add a PageSpeed ​​module.

In the course of the construct, you’ll be prompted to configure further logic for Nginx. Keep in mind the pagespeed folder created in your home directory?

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. >

Include the folder in the creation process. So it would look like this:

--add-dynamic-module=/home/anmol/incubator-pagespeed-ngx-latest-stable

Now, when prompted during construction, combine both the path shown above and the Nginx core module and logic output. The entire line should look like this:

--add-dynamic-module=/home/anmol/incubator-pagespeed-ngx-latest-stable --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/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt="-g -O2 -fdebug-prefix-map=/data/builder/debuild/nginx-1.20.0/debian/debuild-base/nginx-1.20.0=. -fstack-protector-strong -Wformat -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fPIC" --with-ld-opt="-Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now -Wl,--as-needed -pie"

When prompted again, select U For yes.

You have set --with-debug for building nginx, but precompiled Debug binaries for
PSOL, which ngx_pagespeed depends on, aren't available.  If you're trying to
debug PSOL you need to build it from source.  If you just want to run nginx with
debug-level logging you can use the Release binaries.

Use the available Release binaries? [Y/n] Y

With to complete the construction.

After the construction is complete, the Pagespeed module must be included with Nginx. You can test by running the below command:

nginx -V

This will now output a line pointing to the Pagespeed folder with your home directory.

nginx version: nginx/1.20.0
built by gcc 9.3.0 (Ubuntu 9.3.0-17ubuntu1~20.04) 
built with OpenSSL 1.1.1f  31 Mar 2020
TLS SNI support enabled
configure arguments: --add-module=/home/anmol/incubator-pagespeed-ngx-latest-stable --add-dynamic-module=/home/anmol/incubator-pagespeed-ngx-latest-stable --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib/nginx/modules

Next, enable the PageSpeed ​​module and create a symbolic link to the Nginx module.

sudo cp ~/nginx-1.20.0/objs/*.so /etc/nginx/modules
sudo ln -s /usr/lib/nginx/modules /etc/nginx/modules

Finally, add this initial PageSpeed ​​block to the Nginx server block of the website you want to repair. Add to each server block where PageSpeed ​​is enabled:

server {
...
pagespeed on;
pagespeed FileCachePath /var/ngx_pagespeed_cache;

location ~ ".pagespeed.([a-z].)?[a-z]{2}.[^.]{10}.[^.]+" {
  add_header "" "";
}
location ~ "^/pagespeed_static/" { }
location ~ "^/ngx_pagespeed_beacon$" { }
...
}

Exit File Save and reload Nginx

sudo systemctl reload nginx

Test the PageSpeed ​​settings.

curl -I -p http://quofact.com

You should see output similar to the one below

HTTP/1.1 200 OK
Server: nginx/1.20.0
Date: Sat, 15 May 2021 14:58:16 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Tue, 20 Apr 2021 13:35:47 GMT
X-Page-Speed: 1.13.35.2-0 
Cache-Control: max-age=0, no-cache

What should he do More PageSpeed ​​configurations are available from its website. Go to the site to find more configuration options.

Conclusion:

This post showed you how to install the PageSpeed ​​module on Ubuntu with the Nginx HTTP server. If you find an error above, please use the comment form below to report it.

You may also like the post below:

How To Install ElasticSearch 7.x on CentOS 7