NGINX防止缓存JSON文件

aamkag61  于 5个月前  发布在  Nginx
关注(0)|答案(1)|浏览(89)

我有一个在NGINX上运行的Web应用程序。
我正在尝试阻止NGINX缓存JSON、JS、CSS文件。
我的配置如下:

server {
  listen 0.0.0.0:80;
  root /usr/share/nginx/html;
  proxy_connect_timeout       300;
  proxy_send_timeout          300;
  proxy_read_timeout          300;
  send_timeout                300;
  location / {
    try_files $uri $uri/ /index.html;
  }
  location ~* /.(css|js|json)$ {
    expires -1;
    add_header Cache-Control:no-store, no-cache;
  }
}

字符串
当我在浏览器中查看时,我仍然看到文件是(磁盘缓存)。
我做错了什么?
谢谢.
我尝试使用just expires -1;尝试仅对JSON文件应用此过滤器。尝试仅使用no-cache头
而且我不能不从缓存中提供文件。

w6lpcovy

w6lpcovy1#

你可以设置它来绕过它:

location / {
    # your configurations
    # ...

    if ($request_uri ~* \.(json|js|css)$) {
        proxy_cache_bypass 1;
        expires off;
    }
}

字符串

相关问题