Setting up a NGINX RTMP Streaming Server

ESports, or non-technically the broadcasting of computer games for others to watch, has moved to the spotlight recently and is gathering a larger following than expected. Who would have thought that just watching video games would be more popular than actually playing them? As I have been playing Internet multiplayer games since purchasing Quake as a pre-release, the notion that others might be interested in my game was somewhat fascinating. I began streaming a few months ago on Twitch, but began to see more networks pop up and wondered how I could stream to more than one.

Introducing Real Time Messaging Protocol (RTMP), a service that was developed by Macromedia but released as open source after Adobe’s acquisition. One feature of RTMP allows you to stream video, from video-on-demand to direct broadcasting to pushing to other streaming carriers. The pushing to other carriers is what got me moving on RTMP as a viable solution, as I am using Open Broadcaster which is also open source.

Setting up an RTMP server took under an hour, and all feeds were pushing live in that same time frame. This tutorial is for CentOS or other similar varieties; RHEL, Scientific, etc. If you are looking for Ubuntu or LUbuntu, please visit here. Credit to OBS site for providing the baseline instructions, which I ported over to CentOS

Install CentOS 6 32bit minimal with 512mb RAM and 20GB drive space. The minimal install is highly recommended to eliminate the cleanup of Apache, etc. The system requirements were more than enough after testing 4 external feeds.

Install yum updates, GCC and GZIP; mlocate and nano are optional.

yum update -y
yum install unzip gcc mlocate nano -y

Create a subdirectory for the installer stuff, so it can be easily deleted later. Downloaded the required applications and extract them. You can get the latest nginx download here, and the RTMP module always has the latest available using the link below.

mkdir install
cd install

wget http://nginx.org/download/nginx-1.9.0.tar.gz
wget https://github.com/arut/nginx-rtmp-module/archive/master.zip

tar -zxvf nginx*.gz
unzip master.zip

cd nginx*

Now configure, make and make install. You should not receive any errors or missing dependencies.

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

Start the service

/usr/local/nginx/sbin/nginx

To see if NGINX is working, visit you servers homepage and you will see an NGINX start page. Now we move on to add RTMP to NGINX’s config files. The files are located in these directories:

/usr/local/nginx/conf/nginx.conf
/usr/local/nginx/conf/nginx.conf.default

Open the nginx.conf file, scroll to the end and insert the text.

nano -w /usr/local/nginx/conf/nginx.conf
rtmp {
        server {
                listen 1935;
                chunk_size 4096;
                application live {
                        live on;
                        record off;
                }
        }
}

Now restart the service.

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

This part ends the standard install of NGINX and RTMP. Below goes into detail on how to configure the various services you can push your gaming stream to.

First we need to edit OBS (on your PC) for streaming to your custom server. Go to Settings -> Broadcast Settings and change the Streaming Service to “Custom”. Add the server we recently configured in the FMS URL box. The Play Path/Stream Key can be any variable, as it is not used in this tutorial.

Open Broadcaster custom server settings

 

Now add your external sources to push your feed when you go live. Some services only use one server (or smart routing), although Twitch has multiple servers. You can find a list of nearby Twitch servers here. It is suggested you pick one that is closest to your server and not your PC.

All feeds follow the same basics: push rtmp://server_source.tld/streaming_key;

Edit NGINX config.

nano -w /usr/local/nginx/conf/nginx.conf

Insert your stream, example below.

rtmp {
        server {
                listen 1935;
                chunk_size 4096;
                application live {
                        live on;
                        record off;
                        push rtmp://service.one.here/your_stream_key;
                        push rtmp://service.two.here/your_stream_key;
                }
        }
}

Restart NGINX, start your stream on your PC and open any streaming provider you placed in the config. Your streams are now being pushed to multiple sources.

Other minor settings to think about is denying others use of the streaming server and denying local playback direct from server, add the following lines to your configuration. I suggest using a /24 range for your IP, as most ISP’s do not statically assign them.

rtmp {
        server {
                listen 1935;
                chunk_size 4096;

                application live {
                        live on;
                        record off;
                        push rtmp://service.one.here/your_stream_key;
                        push rtmp://service.two.here/your_stream_key;
		        allow publish 123.45.67.0/24;
		        deny play all;
                }
        }
}

Restart NGINX.

If you found this tutorial helpful, please subscribe to my Twitch feed to show your support. Thanks!

Tagged , , , , , , , , , . Bookmark the permalink.

Comments are closed.