A
A
alex_devPY2018-02-25 12:51:02
Nginx
alex_devPY, 2018-02-25 12:51:02

How to stream MP4 with reverse proxy?

Greetings.
I'm trying to raise a small video hosting. The initial data is as follows:
1. Backend server. Ubuntu 16 Server hosts application + content.
Django + UWSGI +
NGINX

user www-data;
worker_processes auto;
pid    /etc/nginx/logs/nginx.pid;

events {
    worker_connections 1024;
    multi_accept on;
       }

http {
  upstream django {
    server 127.0.0.1:8000; 
                  }
  server {
    listen 80;
    server_name XXX.XXX.XXX.191;
    charset     utf-8;
    gzip            on;
    gzip_static     on;
    gzip_comp_level 5;
    gzip_min_length 1024;    
    add_header 'Access-Control-Allow-Origin' '*';
    add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
    add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
    add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range';
    if_modified_since off;   
    add_header Accept-Ranges bytes;


     location /static/ {
         root  /home/tube;
                       }

    #location ~ \.mp4$ {
    #    sendfile           on;
    #    tcp_nopush         on;
    #    sendfile_max_chunk 1m;
    #mp4;
    #mp4_buffer_size     2m;
    #mp4_max_buffer_size 10m;
    #                       }

    location / {
        uwsgi_pass  django;
        include     uwsgi_params;
               }

}
}

2. Front end server. NGINX as a reverse proxy.
user  www-data;
worker_processes  auto;
pid    /etc/nginx/logs/nginx.pid;
events {worker_connections  1024;}
http {
    include       mime.types;
    default_type  application/octet-stream;
    server {
         listen       80;
         server_name  XXX.XXX.XXX.92;
         proxy_http_version 1.1;
         proxy_pass_request_headers      on;
         proxy_set_header X-Real-IP $remote_addr;
         proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
         proxy_set_header X-Forwarded-Proto $scheme;
         #proxy_set_header Upgrade $http_upgrade;
         proxy_set_header Range $http_range;
         proxy_set_header If-Range $http_if_range;
         proxy_no_cache $http_range $http_if_range;
         location / {
                proxy_pass  http://XXX.XXX.XXX.191/;
                    }
        }
    }

There was a problem with the video. This is a set of mp4 videos.
When I load a page with a video in the browser, the page is loaded and loaded in the background a piece of video in 2mb. And that's it. By clicking on play, the video is downloaded in parts. (206) - backend server works more or less correctly.
When I load the same page with a video in the browser through the frontend server, the html is loaded correctly, but the video continues to load in the background to its full size (~150mb). Answer 200. On click, the video starts playing as if from the beginning. Loading again with 200 response.
How to avoid preloading video in the background? Do it like on the backend?
I tried to activate the location ~ \.mp4$ { section
, but in this case, the links to the videos give a 404 response.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dimonchik, 2018-02-25
@dimonchik2013

did you watch it?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question