nginx cache configuration

http{

..........

proxy_cache_key $scheme$proxy_host$request_uri;

proxy_cache_path /tmp/nginx/tv-backend levels=1:2 keys_zone=my_zone:100m max_size=10g inactive=30m

                  use_temp_path=off;

server{

location /api/v2{
  proxy_cache my_zone;
  proxy_cache_valid 200 30m;
    proxy_pass http://tv_integration_v2;
}

}

}

Code description:
proxy_cache_key $uri defines the unique key of the cache, which is used for hash access through the unique key

proxy_cache_path cache file path

levels set the cache file directory level; levels=1:2 means two-level directory

keys_zone sets the cache name and shared memory size

inactive will be deleted if no one is accessed within the specified time. 30m means 30 minutes

max_size is the maximum cache space. If the cache space is full, the resource with the longest cache time will be overwritten by default.
proxy_cache_valid Cache validity time, regardless of whether it is accessed during the inactive time, as long as the cache expires at the proxy_cache_valid time, the data will be re-requested.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325646251&siteId=291194637