Installing Nginx With Pagespeed Support
Pagespeed is nice tools designed to help you optimize the performance of your website. Released by Google with what best for them in mind. Pagespeed is available for Apache and Nginx. It easy to install in Apache but quite trivial to install in Nginx, we must compile our own Nginx with pagespeed module. Here's quick howto install them:
1. Prepare to compile nginx by installing compiler and its common dependencies
apt-get install build-essential libpcre3 libpcre3-dev openssl libssl-dev libperl-dev libxslt-dev libgd2-xpm-dev libgeoip-dev libpam-dev
2. Check latest version of nginx and ngx_pagespeed, Here I'm using Nginx 1.6.1 from stable branch and ngx_pagespeed v1.8.31.4-beta, download and extract it
mkdir nginx
cd nginx
NPS_VERSION=1.8.31.4
wget https://github.com/pagespeed/ngx_pagespeed/archive/release-${NPS_VERSION}-beta.zip
unzip release-${NPS_VERSION}-beta.zip
cd ngx_pagespeed-release-${NPS_VERSION}-beta/
wget https://dl.google.com/dl/page-speed/psol/${NPS_VERSION}.tar.gz
tar -xzvf ${NPS_VERSION}.tar.gz # extracts to psol/
cd ..
NGINX_VERSION=1.6.1
wget http://nginx.org/download/nginx-${NGINX_VERSION}.tar.gz
tar -xvzf nginx-${NGINX_VERSION}.tar.gz
3. Configure it, environment parameters, what to disable and what to enable. You can see install options and full list of modules at nginx website. Configure it one line or if you prefer multi line for readability sake, separate each line with backslash. Here's mine:
cd nginx-${NGINX_VERSION}/
./configure \
--prefix=/etc/nginx \
--sbin-path=/usr/sbin/nginx \
--conf-path=/etc/nginx/nginx.conf \
--pid-path=/var/run/nginx.pid \
--lock-path=/var/lock/nginx.lock \
--http-log-path=/var/log/nginx/access.log \
--error-log-path=/var/log/nginx/error.log \
--http-client-body-temp-path=/var/lib/nginx/body \
--http-proxy-temp-path=/var/lib/nginx/proxy \
--http-fastcgi-temp-path=/var/lib/nginx/fastcgi \
--user=www-data \
--group=www-data \
--without-http_ssi_module \
--without-http_scgi_module \
--without-http_uwsgi_module \
--without-mail_pop3_module \
--without-mail_imap_module \
--without-mail_smtp_module \
--with-http_ssl_module \
--with-http_gzip_static_module \
--with-http_spdy_module \
--with-http_realip_module \
--with-http_geoip_module \
--with-http_image_filter_module \
--with-http_sub_module \
--with-http_flv_module \
--with-http_mp4_module \
--with-http_stub_status_module \
--with-debug \
--add-module=../ngx_pagespeed-1.8.31.4-beta
make && sudo make install
5. Start your nginx, or restart if you have installed it before. On some machine it will cause an error like this
[emerg]: bind() to 0.0.0.0:80 failed (98: Address already in use)
Just kill the process using: