The Raspberry Pi is a credit-card sized computer that plugs into your TV and a keyboard. Several web server softwares are available for Linux-based operating systems including Raspibian, a free operating system based on Debian optimized for the Raspberry Pi hardware. Its very easy to use any of these softwares to turn the Pi to a 24/7 portable server. But due to the hardware limitations, its always a good idea to opt for a lightweight solution when possible and available. Apache is a very popular software, but nginx(pronounced engine-x) is a lightweight alternative. In addition to this, using the RTMP module, we can easily turn the pi to a streaming server.

Unlike Apache, all modules, including the 3rd party modules, should be compiled into nginx. We will download the source for nginx, rtmp module and then compile and install it.

Lets install nginx from apt-get first and then remove it. This way, we will get the startup scripts and dependencies in place.

Go to src folder and create an nginx folder, where we will compile the source.

Now, install some dependencies and configure the installer.

Create the www folder

Install nginx

Check the version

Start the service

Check http://localhost/ and you should get the Welcome to nginx! page.

Now, edit nginx.conf to set the RTMP configuration. My config file looks as below.

The highlighted portion at the end of the file defines the RTMP settings. It essentially add a new application named hls.

Open the virtual server file /etc/nginx/sites-enabled/default for the rest of the configuration. My file looks as below:

The highlighted portion towards the end shows the configuration to add an RTMP statistics page and types served by hls application.

Check http://localhost/stat to see the RTMP statistics page.

You can publish your stream to rtmp://localhost:12345/hls/mystream and clients like VLC player can consume it using the url http://localhost/hls/mystream.m3u8

You can use ffmpeg to publish/transcode streams to the RTMP url. That will be explained in the next post.



3 thoughts on “Nginx based streaming server on Raspberry Pi

  1. fwiw:
    Had trouble with getting version 1.10.2 running on rpi2B+ due to “nginx: [emerg] the INET6 sockets are not supported on this platform in “[::]:80” of the “listen” directive” error.

    Adding the –with-ipv6 switch in ./configure worked for me.

Comments are closed.