[Tutorial] How to install Nginx Pagespeed module

I found a way to upgrade nginx to another apt source that bundles ngx_pagespeed as a dynamic module that can be activated easily.
List of features and modules: nginx modules - deb.myguard.nl - Boost your webserver.

How to install: How to use - deb.myguard.nl (has a few instructions wrong)
Correct install instructions for Ubuntu:

Step 1. Add new nginx source

cd /etc/apt/trusted.gpg.d/
wget https://deb.myguard.nl/pool/deb.myguard.nl.gpg
. /etc/os-release
echo "deb [arch=amd64] http://deb.myguard.nl $VERSION_CODENAME main" >  /etc/apt/sources.list.d/deb.myguard.nl.list
apt update

!!! Warning !!!: Do NOT upgrade yet. You could lose your ssh access here. This apt source provides updates to SSH (openssh-server), and the new update added 2 new configs: /etc/ssh/sshd_config.d/10-algorithms-ciphers.conf and 20-security.conf that in my case disallowed my ssh public key algorithm, and I got error Too many authentication failures on any login attempt.
When you upgrade, it’s very important to choose keep your currently-installed version every time it asks you, and then DO NOT reload ssh service. First delete those 2 new configs, then reload.

Step 2. Upgrade

apt upgrade # select "keep your currently-installed version" every time
rm -f /etc/ssh/sshd_config.d/10-algorithms-ciphers.conf /etc/ssh/sshd_config.d/20-security.conf
service ssh reload

apt update also updates nginx, in my case from 1.23.4-1 to 1.24.0-3

Step 3. Install pagespeed module

Now simply install pagespeed:

apt install libnginx-mod-pagespeed

Now you have 3 new snippets: /etc/nginx/snippets/pagespeed_libraries.conf , pagespeed-main.conf.example and pagespeed-site.conf.example

Step 4. Activate pagespeed nginx config

pagespeed-main must be loaded at the server level. To do this you can copy paste it’s content in conf.d/pagespeed.conf

cat /etc/nginx/snippets/pagespeed-main.conf.example > /etc/nginx/conf.d/pagespeed.conf

Step 5. Activate pagespeed in your desired vhost or template

Now you can activate pagespeed at a vhost level, with a custom nginx config like so: (you can also make a template if you want)
nano /home/<your-username>/conf/web/<your-domain>/nginx.conf_pagespeed.conf
copy paste the contents from /etc/nginx/snippets/pagespeed-site.conf.example

nginx -t
service nginx reload

Happy optimizing :smiley: !

1 Like

Usually you will downgrade as we use mainline instead of stable…

I think it just happens that this month this repo has a newer build, looking at his build schedule.

curl https://nginx.org/packages/mainline/ubuntu/dists/jammy/nginx/binary-amd64/Packages | grep Version
Their latest version for ubuntu jammy is 1.23.4-1 built 28-Mar-2023

curl http://deb.myguard.nl/pool/main/n/nginx/ | grep nginx_
This guy’s latest is 1.24.0-3, built last month 2023-Apr-11

Anyways, in case you do get downgraded you can pin this source to be used always:

printf "Package: *\nPin: origin deb.myguard.nl\nPin-Priority: 501" > /etc