12

I am using nginx to serve videos from the file system. I would like to enable range request.

Currently this is the result returned for my file

curl -I fileurl
HTTP/1.1 200 OK
Server: nginx
Date: Sat, 29 Mar 2014 06:41:41 GMT
Content-Type: video/mp4
Content-Length: 15603963
Last-Modified: Sat, 04 Jan 2014 15:02:26 GMT
Connection: keep-alive
Keep-Alive: timeout=300
Accept-Ranges: bytes

But if I send curl --header "Range: bytes=0-50" fileurl

the whole file is downloaded.

This is the server in nginx config:

server {
            listen 80;
            server_name myserver;
            error_log logs/myserver.error.log;
            access_log logs/myserver.access.log;

            root /srv/myserver;

            #add_header Accept-Ranges;
            add_header Accept-Ranges bytes;
    }

Do I have to enable anything else? How could I allow range requests for the files?

kmitov
  • 1,243
  • 3
  • 11
  • 25
  • 2
    Boring Video I expected a cinema blockbuster under that url :-) – rekire Mar 29 '14 at 06:56
  • I "expected" assistance in the comments :) (Judging could sometimes be boring. Actual competitions are not ;) ). – kmitov Mar 29 '14 at 07:05
  • 1
    I have no experience with nginx I was just interested. In general you should not post real urls, so I cannot rate the video and you have less traffic for the question it's not relevant. – rekire Mar 29 '14 at 07:12
  • Thanks. I will keep that in mind. For the current case I hope that with a real url someone could more easily test the server. – kmitov Mar 29 '14 at 07:14
  • The testing would be only easier if you would allow also modifying the config files, but that is of cause bloody dangerous. – rekire Mar 29 '14 at 07:15
  • You might be right. I have removed the real urls. – kmitov Mar 29 '14 at 07:21
  • @thebravoman What is actually serving the file? Is it nginx or is it being passed to a backend? – Danack Mar 29 '14 at 09:49
  • @Danack - it is nginx – kmitov Mar 30 '14 at 05:54
  • 1
    This issue is crucial for auto-playback of (muted) html5-videos on iOS-devices. – Teson Aug 23 '19 at 15:41

3 Answers3

15

I was able to get range requests working after adding the following line to my nginx site config

    proxy_force_ranges on;

You can read more about it here

Nam G VU
  • 33,193
  • 69
  • 233
  • 372
kn04
  • 159
  • 1
  • 3
  • 1
    Man I love you, I've been struggling to get range requests working on my nginx for hours, tried everything, only your hint worked.. Thanks a million. – Marc Mar 29 '20 at 14:08
4

I have found it - its the option

max_ranges

It was max_ranges 0 at the bottom of the configuration.

kmitov
  • 1,243
  • 3
  • 11
  • 25
  • 1
    Only by default `max_ranges` is not supposed to be zero and you did not show that line in your question! In my case, I have `max_ranges 100;` and it still isn't doing it right. – Alexis Wilke Apr 02 '19 at 22:42
-3

The content type for .m4v files is video/x-m4v, I don't think video/mp4 will work for those.

Chirag Bhatia - chirag64
  • 4,430
  • 3
  • 26
  • 35