Using nginx to serve content directly out of a redis cache Using nginx to serve content directly out of a redis cache nginx nginx

Using nginx to serve content directly out of a redis cache


Maybe something more difficult to setup than Webdis but you can do that directly in the nginx daemon with some extra modules like redis2-nginx-module. You will have to recompile nginx.

There is some good examples of configuration on the home page.

For instance :

# GET /get?key=some_keylocation /get {    set_unescape_uri $key $arg_key;  # this requires ngx_set_misc    redis2_query get $key;    redis2_pass foo.com:6379;}

Of course, with a little more nginx configuration, you can get another URL pattern.

Note that for this example, you will have to compile ngx_set_misc module too.


You should be able to get something by setting up Nginx as a reverse proxy for Webdis.

The way you use Webdis is that you put the whole command in the URL, so to GET the key a you request /GET/a. This means that if everything you want to serve is available using GET you can do something like this in Nginx:

location / {  rewrite ^(.*)$ /GET/$1 break;  proxy_pass http://127.0.0.1:7379/;}

(I'm writing the config off the top of my head here, the syntax might be slightly off).

However, the Webdis project is very young so there's no telling how well it will work, and the responses are JSON documents with some extra fluff that you probably don't want to return.


I know this is an old thread but still, this may be useful for some. I tried the same approach as you having nginx serve from Redis directly without hitting using HttpRedis2Module in nginx. I were happy when I got it working because it was some hassle with it, but when I did some stress-tests I'm afraid that it gave really bad results.

It actually was a bit faster and much more stable to serve using nginx->php->mongodb than just using nginx->redis with the module.