Install NGINX with HTTP/2 and Pagespeed

Install NGINX with HTTP/2 and Pagespeed

[toc] Been playing recently with nginx rather than apache (nginx supports http/2 now as of 1.9.5) and its been quite a nice change with a much cleaner config in my mind. Pagespeed is also quite a nice module from our friends over at google to help automatically optimise content with some quite cool results for me so far. The only downside is that it requires a manual build of nginx although as you can see below this still only take ~5 minutes :)

Install:

First off install prerequisite packages
yum install gcc-c++ pcre-dev pcre-devel zlib-devel make unzipyum install gcc-c++ pcre-dev pcre-devel zlib-devel make unzip

 

Pagespeed:

Then Grab pagespeed and PSOL (update version for latest or wanted version).

cd /tmp
NPS_VERSION=1.9.32.10
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

 

Nginx:

Grab Nginx (update version for latest or wanted version)

cd /tmp
NGINX_VERSION=1.9.5
wget http://nginx.org/download/nginx-${NGINX_VERSION}.tar.gz
tar -xvzf nginx-${NGINX_VERSION}.tar.gz
cd nginx-${NGINX_VERSION}/

 

Compile:

Now lets compile with http/2 and pagespeed :)
./configure --with-http_v2_module --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_stub_status_module --with-file-aio --with-ipv6 --with-cc-opt='-O2 -g -pipe -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic' --add-module=/tmp/ngx_pagespeed-release-${NPS_VERSION}-beta/
make
make install

Testing:

Run nginx -V to confirm we have the functions ready for us (should see http2 and pagespeed in the output)

This is a simple nginx config that would confirm http/2 and pagespeed is there for us to use ok but wouldnt be any good to server any content.

server {
    # Enabling http/2 for v4/6
        listen  www.m00nie.com:443 ssl http2;
        listen [beef::c00b]:443 ssl http2;
    server_name www.m00nie.com;
    root /usr/share/weeeeeee;

    ## activating ngx_pagespeed
    pagespeed on;
    pagespeed RewriteLevel CoreFilters;

    location / {
        }
}

 

Quickly validate it with -t

[root@spdy]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

 

You now have Nginx ready to go with both http/2 and pagespeed! Lost of good documentation around the filters avilable and what they do can be found here https://developers.google.com/speed/pagespeed/module/filters

m00nie :D