I need some kind of shield server in front of my streaming server. I have very basic nginx config for that:
proxy_cache_path /localcache/nginx levels=2:2:2 keys_zone=cache:128m;
server {
listen *:80;
server_name _;
proxy_cache cache;
proxy_cache_lock on;
# Immediately forward requests to the origin if we are filling the cache
proxy_cache_lock_timeout 0s;
# Set the 'age' to a value larger than the expected fill time
proxy_cache_lock_age 5s;
proxy_cache_valid 200 36500d;
proxy_cache_use_stale updating;
proxy_cache_methods GET;
location /streamer/ {
proxy_set_header Host streamser.server.exapmle;
proxy_pass_request_headers off;
proxy_hide_header Cache-Control;
proxy_ignore_headers Cache-Control;
proxy_ignore_headers x-accel-expires;
proxy_ignore_headers expires;
proxy_hide_header etag;
proxy_http_version 1.1;
proxy_cache_key $host$uri$is_args$args;
proxy_set_header Connection "";
proxy_pass https://111.222.333.444;
add_header Set-Cookie chost=$Host;
add_header XX-Cache-Status $upstream_cache_status;
}
}
I want to store entries in the cache forever - just until I purge particular files manually. When I watch the video for the first time I can see that header XX-Cache-Status shows MISS as expected, I see the cache folder growing
sudo du -hs vol/localcache/nginx/
62M vol/localcache/nginx/
when I rewind video I see that XX-Cache-Status changes to HIT - looks ok. But! After some time I find the cache folder getting smaller and smaller:
sudo du -hs vol/localcache/nginx/
42M vol/localcache/nginx/
It looks like the cache is purging but I don't understand why. This happens when video is playing. When I stop playing I find cache folder empty in 10-15 minutes but I see no reasons for that. Please help to fix it.
The problem was in inactive
parameter of proxy_cache_path
directive - it's 10 minutes by default.