nginx 不缓存 json,但缓存 .jpg 文件

nginx doesn't cache json, but caches .jpg file

我的 nginx 服务器如果配置如下:

......
server {
    # Status page
    location /nginx_originserver {
      stub_status on;
    }

    listen 80;

 location ~ ^/1 {
      proxy_pass http://10.10.52.126:1239;
      proxy_cache api_cache;
    }
......
}

在这种情况下,当我浏览 http://localhost/1/thumbnail.jpg 时,图像文件被缓存。但是当我将代理更改为如下所示 returns json 的位置并浏览 http://localhost/1/api_service 时, json 文件未被缓存,为什么只缓存图像文件而不缓存json,如何缓存json文件?

location ~ ^/1 {
  proxy_pass http://10.10.52.126:8090;
  proxy_cache api_cache;
}

你试过了吗proxy_cache_valid 200 1d;:

location ~ ^/1 {
  proxy_pass http://10.10.52.126:8090;
  proxy_cache api_cache;
  proxy_cache_valid 200 1d;
}

Link