How to create a streaming server with Nginx

James Singizi
3 min readMar 27, 2020

Video streaming can be difficult to set up especially if one doesn’t want to use established streaming services. YouTube, Facebook, Twitter, Wowza, and many other services provide streaming services that are suitable for different use cases. There is always that one time when creating a private streaming server that you have total control over is the best option.

Nginx

Nginx is described as “The only all‑in‑one load balancer, web server, content cache, and API gateway”. Most importantly Nginx is a web server more like Apache webserver. It has its own advantages and one of these advantages is the fact that it can be used to easily set up a streaming server.

RTMP

RTMP stands for Real-Time Messaging Protocol. The protocol was developed by Macromedia as a means of streaming audio, video and other content over the web. Macromedia was acquired by adobe which later opened part of the RTMP protocol for public use.

Setting up the server.

Video streaming requires a solid internet connection and a capable server. As with most server-side tasks, I personally prefer Linux based operating systems and, in this case, we will be using Ubuntu.

To install Nginx, update the server with the following command:

sudo apt update

Once the update is complete, install dependencies that will help to make sure Nginx runs on the server

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

Now for the nginx (pronounced “Engine-X”) installation part we will have to compile it from source so that we add the RTMP module to the server software. To achieve this, first navigate to your home directory by issuing the cd command. Once there, download the code using wget with the following command.

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

Once that is done, download the RTMP module from GitHub as follows:

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

Issue the following commands to unpack both files and cd to the Nginx folder

tar -zxvf nginx-1.15.1.tar.gz 
unzip dev.zip
cd nginx-1.15.1

Time to build the nginx server with the RTMP module. This can be achieved by issuing the following commands:

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

Congrats!!! Nginx is installed.

Now, by default, the install folder for Nginx is “/usr/local/nginx”.

To start the server issue the following command:

sudo /usr/local/nginx/sbin/nginx

The server is almost ready now, the only part that is left is changing the config file so that we add RTMP capability. Open /usr/local/nginx/conf/nginx.conf using vim or any text editor of choice and add the following lines at the end of the file.

rtmp {    server {        listen 1935;        chunk_size 4096;        application live {            live on;            record off;        }
}
}

Now restart the server with the following command to make sure the new configuration is loaded:

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

The server is now ready for streams. To test the server, use any streaming software such as OBS Studio or Wirecast. Choose custom server on the streaming software configuration and enter “rtmp://<your server ip>/live” as the server you want to stream to. On the stream key or stream name part just enter anything.

Success, If the streaming software manages to stream then your server is working perfectly well. To view the stream there are a number of options to do so. The stream can be embedded in a webpage or viewed from and player that can play video streams such as VLC or IINA player.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

James Singizi
James Singizi

Written by James Singizi

James is a software developer with more than 3 years experience with PHP and Python. He is passionate about code and software development

No responses yet

Write a response