What's new
IPTV SAT FORUM

This is a sample guest message. Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your own topics and posts, as well as connect with other members through your own private inbox!

How to set up your own private RTMP server using nginx

Status
Not open for further replies.

Vortex

Administrator
Staff member
Administrator
Joined
Mar 30, 2018
Messages
81
Reaction score
41
Points
18
Code:
$ sudo apt-get install build-essential libpcre3 libpcre3-dev libssl-dev

Now a bit of info about nginx (pronounced "engine-X"). nginx is an extremely lightweight web server, but someone wrote a RTMP module for it, so it can host RTMP streams too. However, to add the RTMP module, we have to compile nginx from source rather than use the apt package. Don't worry, it's really easy. Just follow these instructions. :)

From your home directory, download the nginx source code:

Code:
$ wget http://nginx.org/download/nginx-1.15.1.tar.gz

As of this writing, the latest stable version of nginx is 1.15.1. You can find the latest version on the nginx download page.

Next, get the RTMP module source code from git:

Code:
$ wget https://github.com/sergey-dryabzhinsky/nginx-rtmp-module/archive/dev.zip

Unpack/unzip them both, and enter the nginx directory:

Code:
$ tar -zxvf nginx-1.15.1.tar.gz
$ unzip dev.zip
$ cd nginx-1.15.1

Now we build nginx:

Code:
$ ./configure --with-http_ssl_module --add-module=../nginx-rtmp-module-dev
$ make
$ sudo make install

And nginx is installed! By default it installs to /usr/local/nginx, so to start the server run the following command:

Code:
$ sudo /usr/local/nginx/sbin/nginx

And to test to make sure nginx is running, point your browser to http://<your server ip>/ and you should get the "Welcome to nginx!" page.

Step 3: Configuring nginx to use RTMP

Open your config file, located by default at /usr/local/nginx/conf/nginx.conf and add the following at the very end of the file:

Code:
rtmp {
        server {
                listen 1935;
                chunk_size 4096;

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

This is an extremely basic configuration with a "live" application that simply forwards the RTMP stream on
to whoever requests it. You can play with it some more later. Here's the whole configuration guide,
which shows you how to forward streams to other places (such as Twitch), save recordings of uploads, output stats, etc.

Restart nginx with:

Code:
$ sudo /usr/local/nginx/sbin/nginx -s stop
$ sudo /usr/local/nginx/sbin/nginx

Step 4: Testing!

Your server should now be ready to accept RTMP streams! Let's try it out.

Create a new profile in OBS, and change your Broadcast Settings thusly:

Code:
Streaming Service: Custom
Server: rtmp://<your server ip>/live
Play Path/Stream Key: test

You may be wondering where that play path "test" came from. Well, we just made it up, just now. You can basically make up any play path and stream to it, and put that path into an RTMP player, and it will play back. For simple purposes, authentication isn't necessary in my experience.

You should now be able to start streaming to your server. If you hit "Start Streaming" and don't get an error from OBS, that's a good sign.

So how do you watch it? The easiest way to do so is with VLC (v2.1.0 or later). Just Open a Network Stream and enter in rtmp://<your server ip>/live/test as the URL. If it all worked right, then you should now be seeing your stream in VLC!

You now have a working RTMP server! Congrats!

What now?

You can add the stream to OBS itself using the Media source or VLC source, or use something like JWPlayer to play back the RTMP stream on a web site you set up.

You can also use your RTMP server to forward to other streaming services and channels! Underneath the "record off;" line in your nginx.conf, add the following:

Code:
push rtmp://<other streaming service rtmp url>/<stream key>

And any stream streamed to that application will be forwarded on to the other service, as
well as being served up from the server! You can add multiple "pushes" to forward the stream to multiple locations.
 
Status
Not open for further replies.
Top
  AdBlock Detected
Sure, ad-blocking software does a great job at blocking ads, but it also blocks some useful and important features of our website. For the best possible site experience please take a moment to disable your AdBlocker.