Thursday, November 20, 2008

Memcached with nginx on rails

As promised in my last article i m posting the way to configure memcached with nginx. Nothing much to do again

Download memcached from http://www.danga.com/memcached/download.bml you might also require a memcache lib available on http://tangent.org/552/libmemcached.html install both of them and the memcached command will be available to you

just type in this on the terminal

memcached -p 11211
Thats it..now memcache is on. Just few more changes in the nginx.conf file and you r ready to zoom your rails app

you just need to write this


location /dynamic_request {
# append an extenstion for proper MIME type detection
if ($args ~* format=json) { rewrite ^/dynamic_request/?(.*)$ /dynamic_request.js$1 break; }
if ($args ~* format=xml) { rewrite ^/dynamic_request/?(.*)$ /dynamic_request.xml$1 break; }

memcached_pass 127.0.0.1:11211;

error_page 404 = @dynamic_request;

}

Also you might require to set the uri so do this

set $memcached_key $uri;


Ok thats done no restart nginx service and your memcache + mongrel cluster with gzip on will be running and ur rails app will be zoooooooooooooming

Njoi

No comments: