Here at WOTS, we stream to our YouTube channel via an
nginx relay. Out of the box,
nginx doesn’t support RTMP, though. There’s a module you can download – but it’s source only. Since nobody is currently making a PPA for
nginx with RTMP support built in, I build mine from source. It’s not as hard as it sounds – anybody can figure it out! In this article, I’ll archive my scripts for building
nginx with the RTMP module the Ubuntu way.
Normally, to install software on Ubuntu, we’d use something like
synaptic – a package manager that installs binary software someone else built for us. In order to add a module to nginx, we’ve got to compile it against the nginx code for the release of nginx we want to use.
Step one is to grab the latest version of nginx source from the Ubuntu repositories. This ensures that the nginx we build will be compatible with the other Ubuntu packages we have installed already.
# Always a good idea before you start doing apt commands: sudo apt-get update && sudo apt-get upgrade # Grab any build dependencies, this will install all required packages automatically: sudo apt-get build-dep nginx # We'll need git to grab the RTMP module later, and fakeroot for the .deb build sudo apt-get install git fakeroot # Make a directory for our build of nginx: mkdir nginx && cd nginx # Get the source to the nginx package apt-get source nginx
apt-get source nginx command fails, you may have to edit your
/etc/apt/sources.list and uncomment the lines that start with
deb-src. Save the file, then re-run
sudo apt-get update and try the
apt-get source nginx command again.
Now, we need to add the source for
nginx-rtmp-module to the nginx source code:
# Enter the modules directory for this build of nginx. Since the build number will vary, use the wildcard: cd nginx*/debian/modules/ # Clone the git repo for the rtmp module, this copies its source into the Ubuntu nginx sources: git clone https://github.com/arut/nginx-rtmp-module.git # Go back to the top of the nginx source code cd ../../
From here, we need to tell the package build utility that it needs to build
nginx-rtmp-module. For this, you’ll need to edit the file
debian/rules. There are many ways to add this to the build – as of 14.04, Ubuntu builds several packages for nginx. I tend to want to install all of the nginx extras, so I add rtmp to the “extras” build.
Look for a section like
extras_configure_flags in the file. Add the line
--add-module=$(MODULESDIR)/nginx-rtmp-module to the end of this list. Note that the
\ at the end of each line means “continue on to the next line.” You’ll need to add a
\ to the previous line in order to add a new line.
Save this file, and then exit your editor.
At this point, if you want to change the version number (ie, to prevent the “stock” nginx from installing on top of your custom RTMP enabled version) you can. You’ll need to edit
debian/changelog, and add a new section at the top. Follow the same pattern as the other sections in the file, and change the version number to whatever you want. I suggest just adding your initials or similar to the end of the existing version number.
Now we build. From the same
nginx-<version> directory as above:
This may take a while, depending on your hardware. When it is finished, you’ll have a set of .deb files in the directory above
sudo dpkg -i nginx-common_*.deb sudo dpkg -i nginx-extras_*.deb
That should do it! You’ve now installed a custom build of
nginx on Ubuntu that includes the RTMP module!