Compiling nginx with ngx_cache_purge on Ubuntu 15.10

There's a PPA for 15.04 and earlier versions, but I needed nginx with the cache purge module on 15.10. Here are the steps I took:

Install nginx from the Ubuntu repository, then immediately stop the service:

sudo apt-get install nginx
sudo systemctl stop nginx

Download the latest sources for nginx and the ngx_cache_purge module and untar:

wget http://nginx.org/download/nginx-1.9.12.tar.gz
wget http://labs.frickle.com/files/ngx_cache_purge-2.3.tar.gz
for filename in *.tar.gz; do tar zxf $filename; done

Install required libraries (these are the ones I needed to install; YMMV).

sudo apt-get install build-essential libpcre3 libpcre3-dev zlib1g zlib1g-dev libssl-dev libssl1.0.0 libxml2 libxml2-dev libxslt1.1 libxslt1-dev libgd-dev libgeoip1 libgeoip-dev

Build nginx. The options listed here are essentially the same as what are listed in the repository build. The only differences are the addition of the ngx_cache_purge module and the removal of the --with-http_spdy_module (which doesn't work for whatever reason).

cd nginx-1.9.12
./configure --add-module=../ngx_cache_purge-2.3 --with-cc-opt='-g -O2 -fPIE -fstack-protector-strong -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2' --with-ld-opt='-Wl,-Bsymbolic-functions -fPIE -pie -Wl,-z,relro -Wl,-z,now' --prefix=/usr/share/nginx --conf-path=/etc/nginx/nginx.conf --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log --lock-path=/var/lock/nginx.lock --pid-path=/run/nginx.pid --http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-proxy-temp-path=/var/lib/nginx/proxy --http-scgi-temp-path=/var/lib/nginx/scgi --http-uwsgi-temp-path=/var/lib/nginx/uwsgi --with-debug --with-pcre-jit --with-ipv6 --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-http_auth_request_module --with-http_addition_module --with-http_dav_module --with-http_geoip_module --with-http_gzip_static_module --with-http_image_filter_module --with-http_sub_module --with-http_xslt_module --with-mail --with-mail_ssl_module
make
sudo make install

You'll need to replace the Ubuntu repository version of nginx with the one you just compiled. The make install command drops it in /usr/share/nginx/sbin, but it needs to be in /usr/sbin. We'll take care of that now. Then, assuming everything went well, you can restart the nginx service.

sudo mv /usr/sbin/nginx /usr/sbin/nginx.ubuntu
sudo cp /usr/share/nginx/sbin/nginx /usr/sbin/.
sudo systemctl start nginx

You may want to prevent apt from updating nginx (so that you can do it manually). If so, the following commands are useful:

sudo apt-mark hold nginx
sudo apt-mark unhold nginx