1

I have a question/problem weather it is possible to configure a NGINX Reverse Proxy so that it does not Proxy every Request of a Video Stream to the Backend Server, instead Opening a Single Connection to get the Video stream and distribute it to the Clients. Right now i use following configuration.

server {                                                                        
      listen 9000 ssl;                                                              
      server_name some.domain www.some.domain;                                        
      error_log /var/log/nginx/error.cam.log;                                       
      access_log /var/log/nginx/access.cam.log;                                     

      ssl on;                                                                         
      ssl_certificate /etc/letsencrypt/live/some.domain/fullchain.pem;        
      ssl_certificate_key /etc/letsencrypt/live/some.domain/privkey.pem;       

      location / {                                                              

        auth_basic "Login";                                       
        auth_basic_user_file /etc/nginx/auth/Somefile;   
        proxy_pass http://XXX.XXX.XXX.XXX:9000/;                                  
        proxy_http_version 1.1;                                                 
        proxy_buffering off;        

      }                                                                                                                                                                                                                                
}  

Which leads to a new Backend to NGINX Connection with the exact same Video Stream everytime a Client Requests requests that site from the NGINX server. Network Activity Backend=Green , NGINX=Blue Above Graph shows the Outgoing Network traffic: Green=Nginx Server and Blue=Backend Server. Every Peak means a new client accessing the Video MJPG stream.

So the Problem is i have a verry limited Performance from Backend to the NGINX Proxy because the Backend is a Raspberry Pi which cant deliver more that 30Mbit stable stream. I already experimented with buffering etc. but had no success. Is there any method to use a single Connection to the Backend?

Thanks and Regards from Germany, Flo

2

Nginx will always create new proxy connection for incoming connection unless it is cached localy. As MJPG is an infinite loop, it doesn't seem as an option here.

What I would however try is setup a ffmpeg/vlc on the proxy server to consume mjpg stream from rpi. Nginx then can connect to local ffmpeg/vlc to get stream. You will then have only one connection to the backend server.

|improve this answer|||||
  • Thank you for your respons, in my case the (live)stream is a Network camera producing a Mjpg (en.wikipedia.org/wiki/Motion_JPEG) so its an infinite video stream once startet upon closing the connection thats why i dont know how to cache it :) – Flo Jul 6 '16 at 9:10
  • I see, sorry I missed that information. Check the answer again. Hopefully you will find it useful. – Yarik Dot Jul 6 '16 at 10:24
  • Wow thank you , that was the information/hint i needet :) – Flo Jul 6 '16 at 12:20
0

As @Yarik has answered, this is currently not possible with how Nginx handles the proxy. You need some system that is designed to take the one stream and can rebroadcast that to however many clients would like it.

There are some other projects that are designed to fill this void. You could always run one of these behind Nginx on the same server. Nginx will still see individual connections for each client, and forward those to the broadcaster, but the broadcaster will only ever load up the camera with one client.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.