Skip to content

Page 3 Streaming your Desktop on your own Nginx Server

Christophe NUNES edited this page Mar 22, 2017 · 3 revisions

1rst Step

I'm using a Raspberry Pi 3 as Nginx Server, with a Debian LITE distribution.

NOTE : For this tutorial you'll need a Client and a Server (or run Virtual Machines instead).

Connect your Client to your Server with SSH using the following command :

ssh name@IP_server

You can register your server into /etc/hosts. In my case I use :

ssh pixhub@raspi

You are now connected to your server by SSH. Make sure your repositories are updated, and make upgrade of your packages :

sudo apt-get update
sudo apt-get upgrade

You can also upgrade your distribution :

sudo apt-get dist-upgrade

Install Nginx

For this part I totally followed @arut instructions to download and compile latest RTMP module from his git.

You must download utilities to compile Nginx :

sudo apt-get install build-essential libpcre3 libpcre3-dev libssl-dev

Now we'll make a build directory in your HOME and change directory into :

sudo mkdir ~/build && cd ~/build

Now we'll download the Nginx-RTMP-module from @arut's repository :

sudo git clone git://github.com/arut/nginx-rtmp-module.git

If it doesn't work, make sure you got the gitpackage installed :

sudo apt-get install git

And re-launch the download of Nginx-RTMP-module.

Now we'll Download the latest stable version of nginx from their official website, extract the content and change directory into :

sudo wget http://nginx.org/download/nginx-1.10.2.tar.gz
sudo tar xzf nginx-1.10.2.tar.gz
cd nginx-1.10.2

Let start compile Nginx with the RTMP-module :

sudo ./configure --with-http_ssl_module --add-module=../nginx-rtmp-module
sudo make
sudo make install

To Start and stop Nginx :

sudo /usr/local/nginx/sbin/nginx
sudo /usr/local/nginx/sbin/nginx -s stop

Set Live Stream

We'll edit the nginx.conf file to set live streaming up in our Server. I use vim as text editor, but you can use nano instead. But before editing this file, just make a backup of the original config in the same directory :

cp /usr/local/nginx/conf/nginx.conf /usr/local/nginx/conf/nginx.conf.back

Let edit file :

sudo vim /usr/local/nginx/conf/nginx.conf

Just add the following rows at the end of the nginx.conf file :

rtmp {
    server {
        listen 1935;
        ping 30s;
        notify_method get;

        application live {
            live on;
            record off;
            }
      }
}

You can check all the available and configurable options for the RTMP module just right here : https://github.com/arut/nginx-rtmp-module/wiki/Directives

Stop and start Nginx :

sudo /usr/local/nginx/sbin/nginx -s stop
sudo /usr/local/nginx/sbin/nginx

Let Start Streaming with ffmpeg

As we saw in the previous tutorial, you can take the same command line we used for Twitch, just modifying the last row like that :

ffmpeg -f x11grab -s 1920x1080 -r 30 -i :0.0 \
-f alsa -i pulse -vcodec libx264 \
-s 1280x720 -acodec libmp3lame -ac 2 \
-ab 128k -ar 44100 -threads 0 \
-f flv "rtmp://IP_nginx_server:1935/live"

The stream started. Let watch that with VLC for example.

  • Launch VLC.
  • In the tool bar : Media --> Open Network Stream.
  • put : rtmp://IP-nginx_server/live

It works!

Don't forget to press Q to stop streaming.

Finally

Now you know how to install and configure Nginx to stream on it and watch it by the server, in home made mode.

In another tutorial, I'll show you how to configure Nginx to make HLS streaming (HTTP Live Stream) and how to save your videos while streaming to watch it by VOD service.

Thank you for attending this tutorial.

Best regards.

pixhub.