使用Nginx直接从Redis缓存中提供内容 [英] Using nginx to serve content directly out of a redis cache

查看:895
本文介绍了使用Nginx直接从Redis缓存中提供内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用nginx将请求传递给Node应用.该应用程序基本上充当html的远程缓存(检查用户请求的内容是否在redis数据库中,是否只是显示该内容,如果没有,请抓取并将其存储在redis缓存中并提供服务.)

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 just show that, if not grab it and store it in the redis cache and serve it up.)

我很好奇是否有通过让Nginx直接从Redis提供内容来绕过Node应用程序的功能吗?我一直在鬼混http_redis模块,但是我无法真正使它正常工作.

I was curious if there was anyway to bypass hitting the Node app by having nginx serve up the content directly from redis? I have been fooling around with the http_redis module but I can't really get it to work.

一个简单的示例是: http://mywebsite.com/a 其中,nginx会提供内容输入"a"键,如果该键不存在,则将其传递给节点应用程序.这有可能吗?

A simple example would be: http://mywebsite.com/a where nginx would serve the content up in the 'a' key or pass it on to the node app if the key did not exist. Is this even possible?

推荐答案

也许比Webdis设置起来更困难,但是您可以直接在nginx守护进程中使用一些额外的模块(例如

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.

例如:

# 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;
}

当然,有了更多的nginx配置,您可以获得另一个URL模式.

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

请注意,在此示例中,您还必须编译 ngx_set_misc 模块

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

这篇关于使用Nginx直接从Redis缓存中提供内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆