Welcome! Log In Create A New Profile

Advanced

cache 404 but not 200 in same location

Posted by niko78 
This forum is currently read only. You can not log in or make any changes. This is a temporary situation.
cache 404 but not 200 in same location
March 23, 2024 12:20PM
hi,
I use nginx for hls livestreaming. It works well but I have a small challenge and impossible to found how to solve it.
So I disabled cache for m3u8 as it changes every time and I enabled caching for ts for 120s.

My request is that I need also to cache 404 on m3u8 for by example 5 seconds. Why ? because when I have ton of viewers in a live when live did not start yet, nginx forwards requests to my origin server... to get a 404, so instead getting pressure on origin, I would prefer cache 404 just few seconds in waiting 200 (stream ok).
In the end I don't know how to get both in the same time.

so I have a location for m3u8 where
to enable caching for 404, but it seems to cache also 200 by default (I tried "valid 200 0;" without more success)
proxy_cache_valid 404 5s;

to disable caching for all :
proxy_cache off;
expires -1;

fyi my origin sends also a cache-control header with "max-age=1", I tried also to remove it from nginx without success. I would like to avoid put max-age=0 on origin.

If you have an idea
Thanks

Online Users

Guests: 74
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 500 on July 15, 2024
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready