Live and on-demand video had become a normal part of the web, supported by many hosted broadcasting platforms. This article begins a series on building an independent streaming stack for projects that need control over their server, workflow, and distribution path.

Several broadcasting products were available, but each carried a compromise: proprietary software tied the system to a vendor, while some open alternatives used resources poorly or were difficult to operate at scale.

The nginx-rtmp-module adds RTMP streaming capabilities to Nginx. It is not included in the standard web server package and must be compiled alongside Nginx. The module can publish several stream formats, invoke transcoding workflows, and distribute load between servers; it also performed well in practical load tests.

The following procedure builds Nginx with the RTMP module on Debian.

Install the compiler toolchain and required development libraries:

aptitude install  build-essential checkinstall wget git libpcre++-dev libssl-dev install libgeoip-dev install libxslt1-dev

Nginx can use several optional libraries. Remove dependencies for features that will not be included in the resulting server.

Download the source code for the current stable Nginx release:

mkdir –p /usr/build && cd /usr/build
wget http://nginx.org/download/nginx-1.8.0.tar.gz
tar -zxf nginx-1.8.0.tar.gz

Clone the RTMP module source from GitHub:

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

Configure the Nginx build and include the module:

cd ./nginx-1.8.0/
./configure --add-module=/usr/build/nginx-rtmp-module --prefix=/usr/sbin --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-client-body-temp-path=/var/cache/nginx  --http-fastcgi-temp-path=/var/cache/nginx/fastcgi --http-log-path=/var/log/nginx/access.log --http-proxy-temp-path=/var/cache/nginx/proxy --lock-path=/var/lock/nginx.lock --pid-path=/var/run/nginx.pid

Compile and install Nginx:

make && make install

If the same build will be deployed to additional servers, create a package instead of installing directly from the build directory:

make && checkinstall

The resulting package can then be transferred and installed consistently on the other hosts.

Nginx is now ready for the RTMP server configuration, which belongs in the next part of the series.

If this guide was useful, share it with colleagues and send any corrections or questions.

Reproducing this material on another website without the author’s permission is prohibited.