This’s how to recompile nginx with upstream hash module

We need to recompile nginx to support upstream hash module. Because debian based nginx, doesn’t have this module loaded. And we need to download the module from here

First of all, we need to install the software that’s needed to recompile a .deb packages

apt-get install build-essential debhelper fakeroot

Then go to /usr/local/src directory

cd /usr/local/src

Now we need to download the source package of nginx

apt-get source nginx

apt-get build-dep nginx

Before we go to the next step, we need to patch nginx with the patch given

cd /usr/local/src/nginx-0.6.32/

patch -p0 < /path/to/upstream/hash/directory/nginx.patch

Then we go to nginx directory

cd /usr/local/src/nginx-0.6.32/debian

Edit rules to add upstream hash module

vim rules

Add –add-module=/path/to/upstream/hash/directory

Go back to nginx directory

cd ..

Now it’s time for us to compile nginx and take a glass of coffee while waiting

dpkg-buildpackage -rfakeroot

If you found error like

(WARNING: Failed to sign .dsc and .changes file)

That means normal. Just ignore the error msg

Now go back to /usr/src directory

cd /usr/src

You should see a file called nginx_0.6.32-3_i386.deb

Then install our new compiled nginx package

dpkg -i nginx_0.6.32-3_i386.deb

Then lastly we add “fair” module on our nginx.conf

Example

upstream backend {
server server1;
server server2;
hash $http_cookie_username;
}

Congratulations that you have install nginx with fair proxy module on your debian :)

If you don’t want to do that installation, you can download directly precompiled debian nginx package that’s already patched for upstream hash module