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 !