Tuesday, October 06, 2009

using nginx as reverse proxy with http-acceleration (caching)

I had to use nginx on a project recently rather than varnish (needed ssl, virtual hosts etc) but I also needed to accelerate the drupal app behind the proxy because drupal can be soooo slow. here are some methods that i researched. i think i am going to use the first because it is easiest and most familiar (similar to what varnish does)

Proxy_cache methods (most like varnish):

http://www.ruby-forum.com/topic/183590

Nginx docs for proxy_cache:
http://wiki.nginx.org/NginxHttpProxyModule#proxy_cache

Proxy_store method:

Another older type of nginx caching (well its not really caching more like mirroring flat file copies of content) that just stores a copy of the requested uri's output from the upstream server to disk and then serves that copy indefinitley as long as it exists: (great for sites with content that does not change much)

http://lucasforge.2bopen.org/2009/09/caching-dynamic-content-using-nginx/

More info on using something like the above but this post includes a cron script to delete files from the cache after a certain length of time.

http://mark.ossdl.de/2009/07/nginx-to-create-static-files-from-dynamic-content/

The above 2 posts could be combined with a post like this (on nginx and memcachce) to store the repsonses in memcache rather than on disk:
http://www.igvita.com/2008/02/11/nginx-and-memcached-a-400-boost/

The question would be how to create propper key's into the memcache. I think that you could crc the output from the upstream servers and use that concatenated to the full uri for the object as the key. That way when the content changes the crc will change thus invalidating the old key and the old content that was stored with the old key.

Here are some posts about how to create keys for memcached content that changes and invalidating stale content:

http://blog.leetsoft.com/2007/5/22/the-secret-to-memcached

http://nubyonrails.com/articles/about-this-blog-memcached

Nginx docs for proxy_store:
http://wiki.nginx.org/NginxHttpProxyModule#proxy_store


Alternate caching plugin for nginx:

This project is interesting and would be awesome but looks too experimental and I don't read chinese :(

http://code.google.com/p/ncache/

0 Comments:

Post a Comment

<< Home