Setup nginx to video streaming

May 7, 2014 7.9k views
I use nginx to stream video from server. But i get error: net::ERR_CONTENT_LENGTH_MISMATCH in this case: 1. load page (video tag in background download small part of video - 2-3 Mb) 2. wait one-two minutes 3. play video browser download some more content (about 3 Mb) and then raise an error if i do not wait video play without errors how can i fix this error?
4 Answers
Hi Ivan,

If you could provide a little more information, we could probably help you better. Is this just static html with a video tag or are you using some kind dynamic framework? Also could you check the contents of your Nginx error log, most likely located at:


I think that will probably show the real problem. Chances are it is a permissions issue. Is the video file accessible to the user running Nginx?
Additional information:
nginx vhost config:
server {
listen 80;
root /var/www/site;
index off;
access_log /var/log/nginx/media.access.log;
error_log /var/log/nginx/media.error.log;

fastcgi_hide_header Set-Cookie;
expires max;
add_header Cache-Control public;

location /video/ {
root /var/www/site;

error log files clean, no errors

in access log, only successful requests:
ip - - [08/May/2014:18:04:58 +0300] "GET /video/shifts/8-9.mp4 HTTP/1.1" 304 0 "" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.132 Safari/537.36"
ip - - [08/May/2014:18:05:58 +0300] "GET /video/more/cleverclover.mp4 HTTP/1.1" 206 822075 "" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.132 Safari/537.36"

i get errors only in google chrome and opera browsers, in ff, safari, ie - video working good.

i try use amazon s3, videos from amazon servers works fine, no errors. i compare headers from server - headers from my server same as amazon servers.

i try this options:
1. disable gzip
2. set
keepalive_timeout 1200s;
3. set
proxy_http_version 1.1;
proxy_set_header Connection "";

but it makes no difference
Could you post a sample of header?

This bug report in Chrome explains why the problem happens there but not with Firefox. Firefox simply ignores it when the Content-Length header reports something different than the actual length.

How about setting "proxy_buffering off;" ?

This question over on ServerFault might help point you in the right direction:
Andrew SB, thanks for your help!
I solve my issue with this directive:
send_timeout 100m;
this keeps connection for 100 minutes when a client retrieves a video file.
Have another answer? Share your knowledge.