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


now get mod page speed from github and unzip

wget${NPS_VERSION} --no-check-certificate;
unzip release-${NPS_VERSION};

we also need psol lib

cd ngx_pagespeed-release-${NPS_VERSION}-beta;
wget${NPS_VERSION}.tar.gz --no-check-certificate;
tar -xzvf ${NPS_VERSION}.tar.gz;

now we can download nginx configure and install it

wget${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/ --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 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/
expect fork
respawn limit 10 5
#oom never
pre-start script
        $DAEMON -t
        if [ $? -ne 0 ]
                then exit $?
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 *