【问题标题】:Nginx micro caching with JQuery callback带有 JQuery 回调的 Nginx 微缓存
【发布时间】:2017-02-16 18:21:51
【问题描述】:

我在我的 Nginx 服务器上设置了微缓存,以将 API 缓存 2 秒。但是,每次向 API 发出请求时,由于附加了 jQuery 回调参数,Nginx 会看到不同的 url。

示例:

api.example.com/get_heats.php?sheet=105&callback=jQuery222018438785197213292_1475857341748&_=1475857342048

api.example.com/get_heats.php?sheet=105&callback=jQuery222018438785197213292_1475857341748&_=1475857342049

应该在 2 秒内返回相同的值,因为它们都引用工作表 105,但它们不会因为回调和 _ 参数随着每个请求而变化。 Nginx 有没有办法忽略任何其他参数?

【问题讨论】:

  • 发布你的 nginx 缓存配置?可能有一种方法可以匹配正则表达式而忽略 jquery 参数
  • cOle2 - 该链接在没有任何参数的情况下缓存 url。我需要使用一个参数来缓存 URL,而其他参数都没有。

标签: php jquery caching nginx


【解决方案1】:

请尝试以下代码,

server {
   ...
   location ~ \.php$ {
      ...
      set $cache_key $request_uri;
      ...
      if ($args ~ "sheet") {
         set $cache_key $cache_key|$arg_sheet;
      }
      ...
      fastcgi_cache_key $cache_key;
      ...
   }
   ...
}

参考:Learn to implement microcachingfastcgi_cache_key

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-03-04
    • 1970-01-01
    • 1970-01-01
    • 2016-12-31
    • 2014-12-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多