【问题标题】:Nginx bypass cache on specific RESTful endpointsNginx 绕过特定 RESTful 端点上的缓存
【发布时间】:2016-06-02 15:59:34
【问题描述】:

我有以下类型的端点。

/v1/endpoint/{id}/cache

/v1/endpoint/{id}/bypasscache

我想绕过第二个缓存,因为它需要是最新的,同时将我的默认缓存保留在不经常更新的第一个 url 上。

是否可以进行此设置,但使用变量 id?

if ($request_uri ~* "/v1/endpoint/18/bypasscache" ) {
  set $no_cache 1;
}

fastcgi_cache_bypass $no_cache;
fastcgi_no_cache $no_cache;

【问题讨论】:

    标签: caching nginx


    【解决方案1】:

    尝试(对于 1 或 2 个字符宽的数字、大小写 ascii 字母组合的变量 id):

    if ($request_uri ~* "/v1/endpoint/[0-9a-zA-Z]{1,2}/bypasscache" ) {
      set $no_cache 1;
    }
    
    fastcgi_cache_bypass $no_cache;
    fastcgi_no_cache $no_cache;
    

    未经测试,因为我目前无法启动备用网络服务;-)

    其他提示可以在nginx location regex - character class and range of matches的回复中找到

    还有提示 not 当字符串在正则表达式中包含花括号时忘记引用该字符串,因为这些可能会干扰块语法花括号 - 这里是 if .. .

    【讨论】:

      猜你喜欢
      • 2017-08-31
      • 1970-01-01
      • 2020-07-05
      • 2019-02-10
      • 1970-01-01
      • 2021-10-23
      • 2010-09-26
      • 2010-10-19
      • 1970-01-01
      相关资源
      最近更新 更多