Nginx会自动删除设置为有效的caching吗?

我build立了一个Nginx反向代理服务器,服务于另一台服务器上托pipe的mp4文件。 现在一切正常,除了caching。 虽然我有proxy_cache_valid设置为1天( proxy_cache_valid any 1d ),caching将始终自动删除一段时间后(5-10分钟,我认为)。 我的文件大小范围从200 – 1500MB(平均700MB)。

我无法弄清楚configuration有什么问题。 任何事情都可能有帮助

这里是configuration:

 worker_processes auto; worker_rlimit_nofile 100000; events { worker_connections 5000; multi_accept on; use epoll; } http { include mime.types; default_type application/octet-stream; sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 10; keepalive_requests 1024; client_body_timeout 12; client_header_timeout 12; send_timeout 10; proxy_cache_path /tmp/mycache keys_zone=mycache:10m use_temp_path=off; limit_conn_zone $binary_remote_addr zone=addr:10m; server { listen 80; server_name localhost; access_log off; error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } open_file_cache max=10000 inactive=30s; open_file_cache_valid 60s; open_file_cache_min_uses 5; open_file_cache_errors on; client_body_buffer_size 16K; client_header_buffer_size 1k; client_max_body_size 8m; large_client_header_buffers 2 1k; location / { proxy_cache mycache; proxy_max_temp_file_size 1924m; slice 100m; proxy_cache_key $host$uri$slice_range; proxy_set_header Range $slice_range; proxy_http_version 1.1; proxy_ignore_headers X-Accel-Expires Expires Cache-Control Set-Cookie; proxy_cache_valid any 1d; limit_conn addr 5; proxy_pass http://domain2.com/; secure_link $arg_md5,$arg_expires; secure_link_md5 "secret$secure_link_expires$uri"; if ($secure_link = "") { return 403; } if ($secure_link = "0") { return 410; } } } } 

您的问题可以通过修改Nginxconfiguration中的proxy_cache_path设置来解决。 在这里你定义你的商店来保存你的caching对象。 有一个不活动=时间选项将修复:

不活动参数指定的时间内未访问的caching数据将从caching中删除,而不pipe其新鲜度如何。 默认情况下,非活动状态设置为10分钟。

在你的例子中,我将延长到2天的最短时间:

 proxy_cache_path /tmp/mycache keys_zone=mycache:10m use_temp_path=off inactive=2d;