Build ngx_pagespeed from source
The maintained PageSpeed module for nginx now ships as a signed, prebuilt package — there's nothing to compile. If you specifically want to build the legacy open-source module yourself, the steps are further down.
Recommended — install the maintained module from the signed repository. It's prebuilt and pinned to your distribution's nginx: no toolchain, no PSOL, and no rebuild every time you upgrade nginx.
curl -fsSL https://packages.modpagespeed.com/install.sh | sudo sh sudo apt install nginx-module-pagespeed # Debian / Ubuntu sudo dnf install nginx-module-pagespeed # AlmaLinux / RHEL 9Full install guide
Why the maintained module ships prebuilt
The maintained module (mod_pagespeed 1.15) links against the PageSpeed Optimization Library (PSOL), and both PSOL and the module source are commercial — distributed under the Business Source License 1.1, with source publication on the public roadmap. So the maintained build is delivered as a signed binary package rather than a source tree you compile. You get the current module — security patches, WebP and AVIF, Cyclone Cache — without compiling anything.
Building the legacy open-source module
The steps below build Google's archived open-source module, not the maintained one. It has had no security patches since 2020 and none of the current features. Build it only for parity with an existing upstream deployment — for anything in production, install the signed package above.
ngx_pagespeed loads as a dynamic module, built against the exact nginx version it loads into — so rebuild it whenever 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 and build PSOL
The legacy open-source module and its PSOL optimization library are
documented at Google's archived upstream,
apache/incubator-pagespeed-ngx. Clone it and build PSOL
from source per its wiki — this is the heavy part of the build, and the
reason most people install the signed package instead.
(github.com/We-Amp/ngx_pagespeed is the maintained
project's home, where the signed package comes from.)
git clone https://github.com/apache/incubator-pagespeed-ngx.git ngx_pagespeed # Build PSOL from source per the archived upstream wiki: # github.com/apache/incubator-pagespeed-ngx/wiki/Building-PSOL-From-Source
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 maintained module is free to install and evaluate — it fully
optimizes and adds an X-PageSpeed-Warn: unlicensed
header until a license is applied; a commercial license is required
for production use. The legacy open-source module is Apache-2.0 and
free, but unmaintained.