Build ngx_pagespeed from source
Compile the maintained PageSpeed module against your nginx. This is the always-available path — reach for it when you run a custom nginx build, an unsupported distribution, or a pinned nginx version. For most installs, the signed package repository is faster.
nginx loads the module as a dynamic module, which must be built against the exact nginx version it will load into. Build against the source for the nginx version you run in production, and rebuild when you upgrade nginx.
Step 1
Install build dependencies
You need a C/C++ toolchain plus the libraries nginx and the module compile against. On a Debian or Ubuntu host:
sudo apt install build-essential cmake \ libpcre3-dev zlib1g-dev libssl-dev \ uuid-dev gperf libjpeg-dev libpng-dev
On an AlmaLinux or RHEL-family host:
sudo dnf groupinstall "Development Tools" sudo dnf install cmake pcre-devel zlib-devel \ openssl-devel libuuid-devel gperf \ libjpeg-turbo-devel libpng-devel
Step 2
Fetch the nginx source
Download the source tarball for the nginx version you run. Match it to your installed version so the dynamic module is binary-compatible:
# Check the version you run nginx -v # Fetch the matching source (substitute your version) curl -fsSLO https://nginx.org/download/nginx-1.26.3.tar.gz tar xf nginx-1.26.3.tar.gz
Step 3
Fetch the module source
Clone the module source and fetch the matching optimization library (PSOL) it links against. The repository's README pins the PSOL URL for each module release — use the one it specifies:
git clone https://github.com/We-Amp/ngx_pagespeed.git cd ngx_pagespeed # Download the PSOL build the README pins, then unpack it here curl -fsSLO <PSOL_URL from the module README> tar xf psol-*.tar.gz
Step 4
Configure and build as a dynamic module
From the nginx source directory, point configure at the
module and build it. Use --with-compat so the module
loads into a stock distro nginx:
cd ../nginx-1.26.3 ./configure --add-dynamic-module=../ngx_pagespeed --with-compat make modules
The build produces objs/ngx_pagespeed_module.so.
Step 5
Install, load, and verify
Copy the module into the nginx modules directory and load it:
sudo cp objs/ngx_pagespeed_module.so /usr/lib/nginx/modules/
# At the top of nginx.conf, before the events block:
load_module modules/ngx_pagespeed_module.so;
Add a minimal pagespeed configuration (see the
configuration reference), then reload nginx
and confirm the X-Page-Speed header:
sudo nginx -t && sudo systemctl reload nginx curl -sI https://yoursite/ | grep -i x-page-speed
Licensing
The module is free to install and evaluate. A license is required for production optimization: without a valid token, the worker stops optimizing and nginx passes requests through unmodified.