Nginx – Adding PageSpeed Module to installed nginx

mod-pagespeednginxUbuntu

I like to add the Google PageSpeed Module to my nginx webserver on Ubuntu.

This link gives a simple overview https://developers.google.com/speed/pagespeed/module/build_ngx_pagespeed_from_source?hl=de but it only covers the case when you install nginx from scratch.

I already have nginx installed, and when I type the following command line inside my /var/lib/nginx folder I get a "No such file" error:

./configure --add-module=$HOME/ngx_pagespeed-release-1.7.30.4-beta

Best Answer

Your best bet at this issue is to build Nginx from scratch.

Save your nginx config files before to a safe place and then do, assuming you are in Debian:

sudo dpkg -r nginx

If you are in Debian : sudo apt-get install build-essential zlib1g-dev libpcre3-dev

Just make sure you remove Nginx and get the needed libs to build Nginx from source if not in Debian.

The libs and tools are :

gcc-c++ pcre zlib make wget

This next part is system independent.

Get the latest Nginx version :

cd /usr/src/
sudo wget http://nginx.org/download/nginx-1.7.6.tar.gz
sudo  tar xvfvz nginx-1.7.6.tar.gz
cd /usr/src/nginx-1.7.6

Get the latest pagespeed source:

sudo wget https://github.com/pagespeed/ngx_pagespeed/archive/v1.9.32.1-beta.zip

Unpack first the module :

sudo unzip v1.9.32.1-beta.zip

cd ngx_pagespeed-1.9.32.1-beta

Wget the PSOL libs inside the module dir and unpack them there:

sudo wget wget https://dl.google.com/dl/page-speed/psol/1.9.32.1.tar.gz
sudo  tar xvfvz 1.9.32.1.tar.gz

cd back to the nginx source root dir and configure, make and make install. Make sure you change the Nginx user on the configuration stage to one that suits your needs (--user=nginx --group=nginx):

cd /usr/src/nginx-1.7.6

./configure --add-module=/usr/src/nginx-1.7.6/ngx_pagespeed-1.9.32.1-beta --prefix=/usr/local/nginx --sbin-path=/usr/local/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/run/nginx.pid --lock-path=/run/lock/subsys/nginx --user=nginx --group=nginx

When configure stage is done :

sudo make

sudo make install

That will get you the last Nginx version with the last pagespeed mod and libraries ready to rock.

Related Topic