How to make Nginx work with distributed/multiple memcached servers?

agentzh agentzh at
Mon Apr 18 09:15:27 MSD 2011

On Sat, Apr 16, 2011 at 2:09 AM, Andy <nginx-forum at> wrote:
> Hi,
> I want to use Nginx as a caching reverse proxy to a Django website that
> runs behind Nginx over uWSGI.

You can try out ngx_srcache + ngx_memc to do such caching.

> Is it possible for Nginx to use multiple memcached servers to cache the
> dynamic pages generated by Django?

Sure, see these two slide pages for an example:

> If so can you share some example
> config? All the examples I've seen only uses one local memcached
> server.

See above.

> And if it's possible to use multiple memcached servers, who will be
> doing the storing and invalidation of cached pages - Nginx or Django?

If ngx_srcache is used, nginx is doing caching completely.

> And if it's Django, how do i make sure that given the same key, both
> Django and Nginx will hash to the same memcached server?

If you want your python app to access memcached as well, the
recommended approach is to pass the nginx variable holding the hashed
memcached upstream name back to your fastcgi app.

When caching does not even reach your python app, your server will
easily reach 10k ~ 20k req/sec for a simple machine when a cache hit
happens ;)


More information about the nginx mailing list