Like this if we need to force cache some files, this is too hard to use need so many locations. there have any ways use lua to control proxy_cache.
local cache_config = ngx.shared.cache_config
local succ, err = cache_config:set("foo.com", '{["~* \.(js|css|png|jpg|jpeg|gif|ico)$":"365d" ],["~* \.(ts|m3u8)$": "3650d"}')
like this save cache rules to ngx.shared.dict so I can modify cache rules dynamically.
Time and cache parameters I think it is possible to call variables but the first line location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ can be dynamic?
location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
expires 365d;
add_header Cache-Control "public";
proxy_cache my_cache;
proxy_cache_valid any 30m;
proxy_cache_methods GET HEAD;
proxy_ignore_headers Cache-Control;
proxy_hide_header Set-Cookie;
proxy_ignore_headers Set-Cookie;
proxy_pass http://my_upstream;
location ~* \.(ts|m3u8)$ {
expires 3650d;
add_header Cache-Control "public";
proxy_cache my_cache;
proxy_cache_valid any 3650d;
proxy_cache_methods GET HEAD;
proxy_ignore_headers Cache-Control;
proxy_hide_header Set-Cookie;
proxy_ignore_headers Set-Cookie;
proxy_pass http://my_upstream;
在此输入代码...