Using nginx to serve content directly out of a redis cache

前端 未结 3 462
别跟我提以往
别跟我提以往 2020-12-30 04:36

I am using nginx to pass requests to a Node app. The app basically acts as a remote cache for html (checks to see if what the user is requesting is in the redis db, if it is

相关标签:
3条回答
  • 2020-12-30 05:05

    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_key
    location /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.

    0 讨论(0)
  • 2020-12-30 05:11

    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.

    0 讨论(0)
  • 2020-12-30 05:23

    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.

    0 讨论(0)
提交回复
热议问题