nginx memcache for redirecta

agentzh agentzh at gmail.com
Tue Nov 3 06:04:05 MSK 2009


2009/11/3 Fernando Flórez <fernando at funciton.com>:
> 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 (
http://www.grid.net.ru/nginx/eval.en.html ):

        location / {
            eval $my_real_url {
                set $memcached_key $request_uri;
                memcached_pass '127.0.0.1:11211';
            }
            proxy_pass $scheme://127.0.0.1:$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
inefficient.

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

Cheers,
-agentzh





More information about the nginx mailing list