These instructions aren’t mine, but are a slightly modified version of the ones listed on serverfault.com thanks to cwd as a reminder for myself with upcoming Nginx updates.
CD to a location you’re happy to work in with the source files:
cd /usr/src
Install dpkg-dev:
sudo apt-get install dpkg-dev
Add repository:
sudo add-apt-repository ppa:nginx/stable
Edit /etc/apt/sources.list.d/nginx-stable-*.list, add uncomment dpkg-src:
deb-src http://ppa.launchpad.net/nginx/stable/ubuntu release-name-here main
note: (the previous step may have already been automatically performed on Ubuntu >= 12.04 – also make sure that you change release-name-here to reflect your version, the most important part is to uncomment the deb-src field as it will use that to download the source in the upcoming step)
Resynchronize the package index files:
sudo apt-get update
Get sources:
apt-get source nginx
Build dependencies:
sudo apt-get build-dep nginx
Edit nginx-*(version-here)/debian/rules (update the section you want to install, be it light/full/common e.g. extras_configure_flags :=):
--with-threads
Build package:
cd nginx-*(version-here) && dpkg-buildpackage -b
Install packages (change the deb version and OS name as needed):
dpkg --install nginx-common_1.2.4-2ubuntu0ppa1~precise_all.deb dpkg --install nginx-full_1.2.4-2ubuntu0ppa1~precise_amd64.deb