Install NGINX Mod PageSpeed

Installing mod_pagespeed on apache is simpler then on nginx, here we should build nginx from sure with mod page speed, I will write down how to do this on ubuntu but this may work on any other distro

first of all we will need to install dependencies

sudo apt-get install dpkg-dev build-essential zlib1g-dev libpcre3 libpcre3-dev unzip

after lets set mod page speed version at this time it’s 1.9.32.4

NPS_VERSION=1.9.32.4;

now get mod page speed from github and unzip

wget https://github.com/pagespeed/ngx_pagespeed/archive/release-${NPS_VERSION}-beta.zip --no-check-certificate;
unzip release-${NPS_VERSION}-beta.zip;

we also need psol lib

cd ngx_pagespeed-release-${NPS_VERSION}-beta;
wget https://dl.google.com/dl/page-speed/psol/${NPS_VERSION}.tar.gz --no-check-certificate;
tar -xzvf ${NPS_VERSION}.tar.gz;

now we can download nginx configure and install it

NGINX_VERSION=1.8.0;
wget http://nginx.org/download/nginx-${NGINX_VERSION}.tar.gz;tar -xvzf nginx-${NGINX_VERSION}.tar.gz;
cd nginx-${NGINX_VERSION}/;
./configure --prefix=/usr/share/nginx --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --pid-path=/var/run/nginx.pid --lock-path=/var/lock/nginx.lock --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/access.log --user=www-data --group=www-data --without-mail_pop3_module --without-mail_imap_module --without-mail_smtp_module --with-http_stub_status_module --with-http_ssl_module --with-http_spdy_module --with-http_gzip_static_module --add-module=$HOME/ngx_pagespeed-release-${NPS_VERSION}-beta;
make;
make install;

now you need to activate mod add below code into nginx.conf(/etc/nginx/nginx.conf) below listen 80 line and create tmp directory and set user to it

pagespeed on;
pagespeed RewriteLevel CoreFilters;
pagespeed FileCachePath "/var/cache/ngx_pagespeed/";
pagespeed EnableFilters combine_css,combine_javascript,remove_comments,collapse_whitespace;
mkdir /var/cache/ngx_pagespeed/;
chown www-data:www-data /var/cache/ngx_pagespeed/;

after this you should have everything installed, but when we building nginx from source there is no upstart script, create file /etc/init/nginx.conf and insert this in it upstart script from nginx website

# nginx
description "nginx http daemon"
author "George Shammas <[email protected]>"
start on (filesystem and net-device-up IFACE=lo)
stop on runlevel [!2345]
env DAEMON=/usr/sbin/nginx
env PID=/var/run/nginx.pid
expect fork
respawn
respawn limit 10 5
#oom never
pre-start script
        $DAEMON -t
        if [ $? -ne 0 ]
                then exit $?
        fi
end script
exec $DAEMON

now you can start nginx using simple command

initctl start nginx

Leave a Reply

Your email address will not be published. Required fields are marked *