Mar 142011
 

I’m not going have much words to say, here we go..

first download nginx source rpm from this excellent contributor/packager and install the source

$ wget http://centos.alt.ru/pub/nginx/0.9/RHEL/SRPMS/nginx-0.9.5-1.el5.src.rpm
$ rpm -Uvh  nginx-0.9.5-1.el5.src.rpm

Change to /path/rpm/SOURCE and download ngx_cache_purge

$ cd `rpm --eval '%{_sourcedir}'`
$ wget http://labs.frickle.com/files/ngx_cache_purge-1.2.tar.gz

Now we need to modified nginx.spec a bit, so it will include ngx_cache_purge module when compiled

$ cd `rpm --eval '%{_specdir}' `
$ vi nginx.spec

Add ngx_cache_source-1.2.tar.gz module to source list as Source20

Source11:       nginx_mod_h264_streaming-2.2.7.tar.gz
Source20:       ngx_cache_purge-1.2.tar.gz

In %prep section add this line %setup -T -D -a 20

%setup -T -D -a 11
%setup -T -D -a 20
%setup -T -D -a 21

In %build section add this line –add-module=%{_builddir}/nginx-%{version}/ngx_cache_purge-1.2 \

...
    --add-module=%{_builddir}/nginx-%{version}/nginx_upload_module-2.2.0 \
    --add-module=%{_builddir}/nginx-%{version}/ngx_cache_purge-1.2 \
    --add-module=%{_builddir}/nginx-%{version}/nginx_mod_h264_streaming-2.2.7
...


Add these line under make command

mv ngx_cache_purge-1.2/CHANGES ngx_cache_purge-1.2/CHANGES.ngx_cache_purge
mv ngx_cache_purge-1.2/README ngx_cache_purge-1.2/README.ngx_cache_purge

Under %files section add this line %doc ngx_cache_purge-1.2/CHANGES.ngx_cache_purge ngx_cache_purge-1.2/README.ngx_cache_purge

...
%doc nginx-upload-progress-module/CHANGES.nginx_uploadprogress_module nginx-upload-progress-module/README.nginx_uploadprogress_module
%doc ngx_cache_purge-1.2/CHANGES.ngx_cache_purge ngx_cache_purge-1.2/README.ngx_cache_purge

%{nginx_datadir}/
...

save nginx.spec, build all, install rpm binary

$ rpmbuild -ba nginx.spec
$ sudo rpm -Uvh /path/to/RPMS/nginx-0.9.5-1.....rpm

Edit nginx.conf add this location

location ~ /purge(/.*)
{
   allow            127.0.0.1;
   allow            what.ever.ip.you.want.to.allow;
   deny             all;
   proxy_cache_purge    staticfilecache  "$scheme://$host$1";
}

staticfilecache is keys_zone change this to what ever keys_zone you’ve defined in proxy_cache_path
“$scheme://$host$1” is proxy_cache_key

Reload/restart nginx

Here’s example purging from command line

$ lynx -dump -source http://www.kutukupret.com/purge/2011/03/14/build-nginx-rpm-with-ngx_cache_purge-module/
<html>
<head><title>Successful purge</title></head>
<body bgcolor="white">
<center><h1>Successful purge</h1>
<br>Key : www.kutukupret.com/2011/03/14/build-nginx-rpm-with-ngx_cache_purge-module/
<br>Path: /var/lib/nginx/7/cc/772cdb140a788c0cf099c53a21160cc7
</center>
<hr><center>nginx/0.9.5</center>
</body>
</html>

done

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

(required)

(required)

*

This site uses Akismet to reduce spam. Learn how your comment data is processed.