My nginx server if configured like this:
......
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;
}
......
}
In this case, when I browse http://localhost/1/thumbnail.jpg
, the image file is cached. But when I change the proxy to a location which returns json
like below and browse http://localhost/1/api_service
, the json file is not cached, why just the image file is cached but not json, how to cache the json file?
location ~ ^/1 {
proxy_pass http://10.10.52.126:8090;
proxy_cache api_cache;
}
Did you try proxy_cache_valid 200 1d;
:
location ~ ^/1 {
proxy_pass http://10.10.52.126:8090;
proxy_cache api_cache;
proxy_cache_valid 200 1d;
}