Install NGINX with HTTP/2 and Pagespeed

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 🙂


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



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

cd /tmp
unzip release-${NPS_VERSION}
cd ngx_pagespeed-release-${NPS_VERSION}-beta/
tar -xzvf ${NPS_VERSION}.tar.gz



Grab Nginx (update version for latest or wanted version)

cd /tmp
tar -xvzf nginx-${NGINX_VERSION}.tar.gz
cd nginx-${NGINX_VERSION}/



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 install


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 ssl http2;
        listen [beef::c00b]:443 ssl http2;
    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

m00nie 😀