nginx memcache for redirecta

agentzh agentzh at
Tue Nov 3 06:04:05 MSK 2009

2009/11/3 Fernando Flórez <fernando at>:
> Hello,
> I would like to know if i could use nginx's memcache module to store urls so
> i can create redirects based on variables.
> Is this possible?

Yes, it's possible, with the excellent "eval" module ( ):

        location / {
            eval $my_real_url {
                set $memcached_key $request_uri;
                memcached_pass '';
            proxy_pass $scheme://$server_port$my_real_url;

assuming you have memcached set up at localhost:11211. Then store the
key-value pair /blah and /foo in your memcached:

   $ set-memcached localhost:11211 /blah /foo

And access your nginx server this way:

   $ curl 'http://localhost/blah'

You'll get the results of the location /foo.

Here I use "proxy_pass" in the example above because I dunno if
there's a config file level directive for the nginx C function
ngx_http_internal_redirect. Using a "proxy" here is rather

I'll add one (named echo_exec) later to my "echo" module anyway.


More information about the nginx mailing list