I'm using X-Accel to serve protected content, using X-Accel-Redirect.
Is it possible to serve only a part of the file? for example, bytes range 0-x, or first 5 minutes of a video (my final goal)
It's important to do that on the server-side, so the client will not have access to the rest of the file.
Currently this is how I send the whole file:
X-Accel-Cache-Control: no-store, no-cache, must-revalidate
Pragma: no-cache
Content-Type: application/octet-stream
Content-Length: {file_size}
Content-Disposition: attachment; filename="myfile.mp4"
Accept-Ranges: bytes
X-Accel-Buffering: yes
X-Accel-Redirect: /protected/myfile.mp4
Nginx conf:
location /protected {
internal;
alias /dir/of/protected/files/;
if_modified_since off;
output_buffers 2 1m;
open_file_cache max=50000 inactive=10m;
open_file_cache_valid 15m;
open_file_cache_min_uses 1;
open_file_cache_errors off;
}
I haven't tested
SliceandX-Acceltogether. If each file can have a different limit defined by the backend you might configure Slice in the location and send the limit with theX-Accel-RedirectURL as below:Nginx.conf
A global file limit
You would need to redirect the original request including the Slice parameters to truncate the file being served.
Nginx conf:
If the
rewritedirective above doesn't work, I suggest the following option usingproxy_pass.