Nginx绕过特定URI的缓存

时间:2018-09-27 08:57:46

标签: nginx caching nginx-location nginx-reverse-proxy nginx-config

要绕过特定uri(例如包含latest1.0的uri缓存),我设置了以下配置:

location ~* ^/api/service/([a-zA-Z0-9.-]+)$ {    
  return 301 $scheme://$http_host$uri/index.html;
}
location /api/service/ {
  set $cache "public, max-age=43200";
  if ($request_uri ~* ^/api/service/([a-zA-Z0-9./]+)) {set $cache "nocache"; }
  proxy_set_header Cache-Control $cache;
  proxy_cache api;      
  proxy_cache_key $request_uri;
  proxy_pass http://backend/some/uri/;
}

因此,我希望缓存将用于/api/service/1.0-12之类的uri,而不会用于/api/service/1.0/api/service/latest,但它不起作用。在这种情况下如何设置缓存?

0 个答案:

没有答案