Configuring VirtualBox As A nginx RTMP Server

      No Comments on Configuring VirtualBox As A nginx RTMP Server

Intro

This is how I went about building a version of nginx that supports RTMP media streaming on an Ubuntu 16.04 VirtualBox.   It is not a simple plug-and-play exercise but anyone with basic Linux system admin skills can get this going.

Initial Setup

Get the latest version of VirtualBox.

Install VirtualBox extensions.

Download Ubuntu 16.04 (AMD64).

Install VirtualBox by mounting the ISO.

Virtualbox Machine Settings – network adapter – advanced – port forwarding.
Forward port 2322 on 127.0.0.1 to port 22 on guest.

Start VirtualBox.

Login via the VirtualBox console and install stuff…

Start by adding the source libraries since we will need to build the RTMP protocol support into nginx from the source files. Edit the /etc/apt/sources.list file and uncomment any lines starting with deb-src where the deb line immediately above it is uncommented.

Now update stuff and install stuff.

Now go get the source for nginx and the nginx-rtmp protocol. We will want a separate directory for all of this stuff.

Tell the nginx builder we want some special modules included. We’ll need to edit the debian/rules file in the nginx* source directory we just got a moment ago. Openthe

Keep in mind that if you automatically or manually update nginx on this server it will overwrite your custom-baked RTMP friendly version.   You can edit the source debian/changelog file and add a new version at the top.   Copy the first block of code and add -rtmp- to your version.  Here is what my config section looks like in debian/changelog:

Build it:

Move your RTMP-enabled nginx build to a good place:

Configure nginx for RTMP

From the command line of Ubunutu:

Add this section above the http{…} section:

Start nginx from the command line:

Start RTMP-enabled nginx

Install (and start) the new packages.

If your server is setup to auto-start nginx this new RTMP enabled version should start by default.  You can check this by running netstat:

You should see port 1935 on the list of ports being listened to.

netstat-a-2016-11-27_10-22-57

These commands can test that nginx is running and start it if necessary:

 

Connecting To The VirtualBox RTMP

In the VirtualBox machine settings you will want to makes sure your network is setup as attached to NAT with the advanced port forwarding option enabled.   Forward your host system’s localhost address (127.0.0.1) port 1935 to the guest port 1935.

virtualbox-rtmp-port-forwarding-2016-11-27_10-21-39

Meta

VirtualBox

The virtual machine service that lets us run a server from our laptop; in my case an Ubunutu 16.04 box on my MacBook Pro laptop.

https://www.virtualbox.org/

Ubuntu

A Linux operating system based on the Debian “flavor”.   Linux operating systems tend to play nice in virtual machines, unlike Windows or OS/X.

https://www.ubuntu.com/

openssh-server

The ssh protocol handler that allows us to connect via SSH to the VirtualBox.   I like to use the built-in OS/X terminal (or PuTTY on Windows) to connect to my virtual machines.   Far less input switching and graphics issues to deal with using a native terminal window on the host machine.

nginx

A media and web server.  Typically used to “hand out” web pages it can send media files like images, videos, and audio streams to users.   The default support is for HTTP requests which is primarily for serving static file requests, meaning you can not pause and restart the request easily.   RTMP protocol support needs to be added.

RTMP

A real time streaming media protocol.   It was originally a proprietary Flash protocol that was partially released as open source by Adobe.   Similar to what http is for web pages, rtmp is for video and audio files.  For tech geeks it is a TCP based protocol meaning it is stateful and can maintain persistent connections.

https://en.wikipedia.org/wiki/Real-Time_Messaging_Protocol

port 1935

The port we are using for nginx audio streaming as configured in the nginx.conf file.  It is the default listening port for RTMP.

Leave a Reply