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

查看:25
本文介绍了使用 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 守护进程中使用一些额外的模块来完成,比如 redis2-nginx-module.您将不得不重新编译 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天全站免登陆