I have to serve .mp4 files through Nginx on a portable Jetson machine. .mp4 files are fragmented MP4 that grow over time (recordings). I would like to be able to serve them with byte-range download and optimal caching (I found that slice-by-slice might be a good idea (https://www.nginx.com/blog/smart-efficient-byte-range-caching-nginx/#cache-slice).
At the moment, my config (/etc/nginx/sites-enabled/default
) looks as follows:
proxy_cache_path /tmp/my_cache keys_zone=my_cache:10m;
server {
listen 80 default_server;
listen [::]:80 default_server;
root /;
index index.html index.htm index.nginx-debian.html;
server_name _;
location /api {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://localhost:4000;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
client_max_body_size 100M;
}
location ~ ^/external/(.*)$ {
proxy_force_ranges on;
proxy_cache my_cache;
proxy_ignore_headers Set-Cookie;
proxy_hide_header Set-Cookie;
slice 1m;
proxy_cache_key $host$uri$slice_range;
proxy_set_header Range $slice_range;
proxy_http_version 1.1;
proxy_cache_valid 10m;
proxy_cache_min_uses 1;
proxy_pass http://127.0.0.1;
root /media/nvidia;
try_files /$1 =404;
}
location / {
proxy_force_ranges on;
proxy_cache my_cache;
proxy_ignore_headers Set-Cookie;
proxy_hide_header Set-Cookie;
slice 1m;
proxy_cache_key $host$uri$slice_range;
proxy_set_header Range $slice_range;
proxy_http_version 1.1;
proxy_cache_valid 10m;
proxy_cache_min_uses 1;
proxy_pass http://127.0.0.1;
root /var/www/html;
try_files $uri $uri/ =404;
}
}
The problem is that after requesting file chunks, there is nothing coming up in the /tmp/my_cache
folder, and the requests similar amount of time.
What am I doing wrong?
Thanks