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

agentzh agentzh at
Wed Apr 20 08:15:14 MSD 2011

On Wed, Apr 20, 2011 at 12:11 PM, agentzh <agentzh at> wrote:
> Another way is to use Lua to pick up a memcached backend from your
> memcached cluster, such that you can define your own hashing
> algorithm, including your custom consistent hashing ones.

Here's an example for defining custom backend routing rules in Lua (by
means of our ngx_lua module) from my slides:

Well, you can also use the arrow keys or pageup/pagedown keys to
switch pages in my (ajax-based) slides.

> Here we use fastcgi_param to pass nginx variable $backend to your
> fastcgi app such that your fastcgi app can read that from its
> environment MEMC_BACKEND. Another approach is to append the $backend
> value to the query string of the forwarded http request.

Basically it's as simple as

    fastcgi_param QUERY_STRING "$query_string&_memc_backend=$backend";


More information about the nginx mailing list