2

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
paskster
  • 301
  • 5
  • 12

3 Answers3

1

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.

Pyth Phytho
  • 63
  • 1
  • 2
  • 8
  • Hi, I know this is a very old thread, but I have a question, I have followed your guide to install nginx version 1.10.2. So I would like to know, do I need to load modules " include /usr/share/nginx/modules/*.conf;" in "etc/nginx/nginx.conf" or it's automatically loaded with your method of configuration? – dswong Sep 18 '17 at 07:20
0

You can use a custom PPA source to install nginx build with Pagespeed to your system.

Look at https://launchpad.net/~sandyd/+archive/nginx-current-pagespeed for the custom build.

Tero Kilkanen
  • 34,499
  • 3
  • 38
  • 58
0

Looks like this requires a number of commands execute if you don't want to build NGINX from scratch. Here is the bash script I'm using for automatic installation of PageSpeed to an already-running NGINX instance:

#!/bin/bash
# https://www.majlovesreg.one/tag/code/
# https://www.majlovesreg.one/adding-pagespeed-to-a-running-nginx-instance

# For custom NGINX version, use:
# ngver=1.14.2
# For passing via the command line, use:
# ngver=$1
# For automated detection of installed NGINX, use:
ngver=$(nginx -v 2>&1 | grep -oP '(?<=/).*')

moddir=/usr/share/nginx/modules
builddir=$(mktemp -d)

# Build in tmp directory
cd ${builddir}

# Use script provided by pagespeed
nice -n 19 ionice -c 3 bash <(curl -f -L -sS https://ngxpagespeed.com/install) -n ${ngver} -m -b ${builddir} -a '--with-compat' -y || { echo '!! error with module creation, exiting...'; exit 1; }

# Replace ngx_pagespeed.so if exists, otherwise, copy it
[ -f ${moddir}/ngx_pagespeed.so ] && sudo mv ${moddir}/ngx_pagespeed.so ${moddir}/ngx_pagespeed.so.old
sudo chmod 644 /usr/local/nginx/modules/ngx_pagespeed.so || { echo '!! error with module path, exiting...'; exit 2; }
sudo cp /usr/local/nginx/modules/ngx_pagespeed.so ${moddir}/

# If new module works well, clean up build and install files
sudo nginx -t && { sudo rm -r /usr/local/nginx; rm -r ${builddir}/incubator-pagespeed-ngx-latest-stable; rm -r ${builddir}/nginx-${ngver}; } || { echo '!! nginx conf failed, exiting...'; exit 4; }

# Restart NGINX
systemctl is-active nginx && sudo systemctl restart nginx || sudo systemctl start nginx
echo
systemctl --no-pager status nginx
echo
echo 'Build and install of ngx_pagespeed sucessful!'
echo

To enable the dynamic module and to set other PageSpeed settings, see: https://www.majlovesreg.one/adding-pagespeed-to-a-running-nginx-instance

Majal
  • 156
  • 1
  • 8