【问题标题】:How can I have nginx return 304 Not Modified based on a Redis cache?如何让 nginx 基于 Redis 缓存返回 304 Not Modified?
【发布时间】:2012-08-28 19:45:00
【问题描述】:

我正在考虑设置 Redis 缓存以加速使用 nginx 部署的 Ruby on Rails 应用程序。我希望 nginx 基于 Redis 数据库中的时间戳(例如上次修改)或基于密钥的存在发送 304 Not Modified。到目前为止,我发现的唯一一件事是如何在 Redis 中缓存整个页面,例如 HttpRedis 模块中的以下示例:

server {
  location / {
    set $redis_key $uri;

    redis_pass     name:6379;
    default_type   text/html;
    error_page     404 = /fallback;
  }

  location = /fallback {
    proxy_pass backend;
  }
}

有人知道这是否可能吗?或者您会推荐另一种无需进入 Rails 堆栈即可发送 304 响应的方法?

【问题讨论】:

    标签: ruby-on-rails caching nginx redis http-status-code-304


    【解决方案1】:

    您应该可以使用HttpRedis2ModuleHttpLuaModule 来执行此操作。

    【讨论】:

    • 谢谢,这看起来确实可行。不幸的是,我想这也意味着从源代码编译我的 nginx。我会看看它是否有效。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-02-12
    • 2013-12-22
    • 2014-01-25
    • 2010-12-07
    • 2012-08-04
    • 1970-01-01
    • 2016-08-08
    相关资源
    最近更新 更多