[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

I need your help… I install all according tutorial, but now i have a strange problem with ssl: when i opened domains i got error with SSL certificate (invalid SSL on cloudflare, first domain) and Connection not secure (second one. I switch off cloudflare proxy on this domain). Both domains configured as proxy for odoo (standard hestia template) and its no connection now…
Nginx config is ok (nginx -t). Hestia domain (login to panel) worked good, no any issues.

I have no idea whats wrong…

root@dc3:/var/log# nginx -V
nginx version: nginx/1.25.1 (nginx modules - deb.myguard.nl - Boost your webserver.)
built with OpenSSL 3.0.8+quic 7 Feb 2023
TLS SNI support enabled
configure arguments: --build=nginx modules - deb.myguard.nl - Boost your webserver. --conf-path=/ etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-client-bod y-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-log-path=/var/log/nginx/access.log --http-proxy-temp-path=/var/lib/nginx/ proxy --http-scgi-temp-path=/var/lib/nginx/scgi --http-uwsgi-temp-path=/var/lib/ nginx/uwsgi --lock-path=/var/lock/nginx.lock --modules-path=/usr/lib/nginx/modul es --pid-path=/run/nginx.pid --prefix=/usr/share/nginx --with-cc-opt=‘-g -ffile- prefix-map=/build/nginx-1.25.1=. -flto=auto -ffat-lto-objects -flto=auto -ffat-l to-objects -fstack-protector-strong -Wformat -Werror=format-security -O3 -flto - DNGX_HTTP_HEADERS -DNGX_ZLIB_NG=1 -D_FORTIFY_SOURCE=2 -w -DTCP_FASTOPEN=23 -fPIC -Wdate-time -D_FORTIFY_SOURCE=2’ --with-compat --with-file-aio --with-http_dav_ module --with-http_gzip_static_module --with-http_auth_request_module --with-htt p_realip_module --with-http_slice_module --with-http_ssl_module --with-threads - -with-http_v2_module --with-http_v3_module --with-ld-opt=‘-Wl,-Bsymbolic-functio ns -flto=auto -ffat-lto-objects -flto=auto -Wl,-z,relro -Wl,-z,now -fPIC -static -libstdc++ -flto -lpcre’ --with-http_sub_module --with-http_stub_status_module
root@dc3:/var/log# nginx -t
nginx: [warn] the “listen … http2” directive is deprecated, use the “http2” di rective instead in /etc/nginx/sites-enabled/default:13
nginx: [warn] the “listen … http2” directive is deprecated, use the “http2” di rective instead in /etc/nginx/sites-enabled/default:14
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

I came across this error recently. I can’t remember how i fixed it.
Can you take a look at service nginx status
And try service nginx restart then status again.

Thank you! I find the cause: Due install new version of nginx changed current configs.
Maybe it will be helpfull to someone) Just need to have backups configs of /etc/nginx

I add pagespeed module to nginx configuration, after this add filters to host template, reload services and start odoo (crm based on python), its used ports 8069 and 8072. Nginx worked as proxy.
My idea is to achieve Odoo site optimization through using pagespeed module in nginx. But my configuration doesn’t work for some reason… I see that the pagespeed is enabled on the domain (checking in browser console), but the site is not optimized by the filters. I don’t understand what is the reason.

Try with a simple static website or some cms like wordpress, to see if the problem is the pagespeed configurations or odoo config, or the proxy config.
Did you follow their official configuration guide ? System configuration — Odoo 16.0 documentation
You can also try disabling gzip, sometimes pagespeed doesn’t work because of it.

Do not use the repo in this tutorial if you are using Ubuntu Jammy.

The OpenSSH packages for jammy have been erroneously built against OpenSSL 3.0.8 instead of 3.1.2.

You will lose access to SSH as this will cause a version mismatch.

1 Like

Does it work for Apache + nGinx?

I don’t know. Did not test this.
Could be worth considering the apache module instead.
They have already built packages for apache on their website: Installing From Packages

Please note, OpenSSH has been completly removed from that repo, and no more version mismatches.