NGINX with RTMP on Raspberry Pi as a streaming server for OBS

Published by Tobias Hofmann on

3 min read

Some time passed since I last wrote about OBS. In 2014, I started using OBS as a streaming solution for an event in Sao Paulo. I had quite some time to convince the co-organizers that streaming to an app and YouTube at the same time is a good idea, and that OBS is a good software for achieving this. In the end, my idea was accepted and SITSP video was captured with OBS and streamed through NGINX to YouTube. I even managed to provide live streaming to iPhone devices via an event app I wrote! OBS was not a very well-known software in 2014, and today it is like the de-facto standard for YouTubers when it comes to streaming game videos. 5+ years later and my architecture is still valid and an example of good solution architecture (and another proof of my visionary skills).

End of 2019 I decided to record videos: capture content of a computer with OBS and stream it to NGINX and recapture it with OBS or watch it with VLC. As my 2014 architecture is still valid, I decided to use my old solution architecture, review it and update it where necessary.

NGINX installation

Debian has a package for NGINX and RTMP. My Raspberry Pi is using the armv7l architecture (uname -m), and for that architecture, the RTMP module is available for Debian buster. If you are not on buster, consider upgrading Raspbian. It’s easier to install software via apt than having to compile it manually.

sudo apt-get update
sudo apt-get install libnginx-mod-rtmp

NGINX configuration

During the installation, NGINX will be started. This fails in my case, as I already have a web server (Apache) running. The port 80 is already used and NGINX startup fails. This is OK, as I do not want NGINX as a web server, just for RTMP and OBS.

To solve this “problem”, I’ll change NGINX configuration and deactivate the HTTP server listening on port 80. The NGINX configuration is located in directory /etc/nginx/.

  • The master configuration file is nginx.conf, where the http connector is configured.
  • The actual server is located in /etc/nginx/sites-enabled/default. Here the local server is configured to listen on port 80.

Deleting this symlink in sites-enabled will deactivate the localhost server and NGINX will start, as it now no longer tries to start a server on port 80 (that is already in use by Apache).

sudo rm sites-enabled/default
sudo systemctl start nginx.service
sudo systemctl status nginx.service

Status so far: NGINX is installed and running. Next task is to enable RTMP.

Enable RTMP

Create file rtmp.conf in /etc/nginx/. In this file will contain the RTMP server configuration. The configuration will make RTMP listen on port 1935 and expose a RTMP URL named live. This is the URL RTMP clients will connect to.

sudo vim rtmp.conf

Add content.

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

Enable RTMP configuration in NGINX. Change nginx.conf to load the above created rtmp.conf file. Add the following line at the top of the file to load the above created rtmp.conf file.

include /etc/nginx/rtmp.conf;

Start NGINX with RTMP

sudo systemctl stop nginx.service
sudo systemctl start nginx.service
sudo systemctl status nginx.service

This should restart NGINX and show no errors. To see if NGINX is now listening on port 1935 for RTMP, you can use netstat.

netstat -an | grep 1935

OBS configuration

After performing all the above tasks, NGINX with RTMP is up and running. Now you can connect OBS to it.

Server: rtmp://192.168.0.164:1935/live
Key: test

Start streaming in OBS. To see if it works, start VLC and connect to rtmp://192.168.0.164:1935/live/test The content OBS captures and streams should now be shown in VLC. There is a lag of a few seconds. This is normal, as the content is buffered.

Let the world know

Tobias Hofmann

Doing stuff with SAP since 1998. Open, web, UX, cloud. I am not a Basis guy, but very knowledgeable about Basis stuff, as it's the foundation of everything I do (DevOps). Performance is king, and unit tests is something I actually do. Developing HTML5 apps when HTML5 wasn't around. HCP/SCP user since 2012, NetWeaver since 2002, ABAP since 1998.

15 Comments

Donald Reynolds · April 1, 2020 at 04:42

I’m having troubles getting NGINX running with RTMP… In the process above do I need to install NGINX separately in advance? I didn’t and I expect that the steps above install a complete version of NGINX that is RTMP enabled. Is that correct?

    Tobias Hofmann · April 1, 2020 at 12:49

    The command “apt-get install libnginx-mod-rtmp” installs nginx with rtmp enabled. The output shows the additionals files selected (e.g. nginx-common, nginx-full).

Matthew · April 4, 2020 at 15:27

Tobias, thankful I came across your site. I’ve followed your install instructions for RPi 4 (Linux raspberrypi 4.19.97-v7l+ #1294 SMP Thu Jan 30 13:21:14 GMT 2020 armv7l GNU/Linux) but NGINX won’t get beyond the initial load …any help would be most appreciated!

The systemctl status shows this:

pi@raspberrypi:~ $ systemctl status nginx.service
● nginx.service – A high performance web server and a reverse proxy server
Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Sun 2020-04-05 00:07:50 AEDT; 13s ago
Docs: man:nginx(8)
Process: 1702 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=203/EXEC)

Apr 05 00:07:50 raspberrypi systemd[1]: Starting A high performance web server and a reverse proxy server…
Apr 05 00:07:50 raspberrypi systemd[1702]: nginx.service: Failed to execute command: No such file or directory
Apr 05 00:07:50 raspberrypi systemd[1702]: nginx.service: Failed at step EXEC spawning /usr/sbin/nginx: No such file or directory
Apr 05 00:07:50 raspberrypi systemd[1]: nginx.service: Control process exited, code=exited, status=203/EXEC
Apr 05 00:07:50 raspberrypi systemd[1]: nginx.service: Failed with result ‘exit-code’.
Apr 05 00:07:50 raspberrypi systemd[1]: Failed to start A high performance web server and a reverse proxy server.

    Tobias Hofmann · April 8, 2020 at 09:41

    Hi Matthew,

    it seems that the start script cannot find the nginx binary at /usr/sbin/nginx. Is the file available?Try to install nginx via apt again.

Warren · April 7, 2020 at 18:56

Thanks Tobias. That looks like a solution for my attempts, too. But I do encounter similar problems like Matthew.
No errors when installing nginx on latest Raspian Buster lite. But it won’t start then automatically.Only get from

sudo systemctl start nginx.service
Job for nginx.service failed because the control process exited with error code.
See “systemctl status nginx.service” and “journalctl -xe” for details.
pi@raspberrypi:~ $ systemctl status nginx.service
● nginx.service – A high performance web server and a reverse proxy server
Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Tue 2020-04-07 16:06:40 BST; 37s ago
Docs: man:nginx(8)
Process: 987 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=

Apr 07 16:06:40 raspberrypi systemd[1]: Starting A high performance web server and a reverse proxy serve
Apr 07 16:06:40 raspberrypi systemd[987]: nginx.service: Failed at step EXEC spawning /usr/sbin/nginx: N
Apr 07 16:06:40 raspberrypi systemd[1]: nginx.service: Control process exited, code=exited, status=203/E
Apr 07 16:06:40 raspberrypi systemd[1]: nginx.service: Failed with result ‘exit-code’.
Apr 07 16:06:40 raspberrypi systemd[1]: Failed to start A high performance web server and a reverse prox

    Tobias Hofmann · April 8, 2020 at 09:46

    Hi Warren,

    what happens when you run “sudo nginx -t”? Nginx should check the configuration and also show you which config files are used. For further information, running just sudo nginx should start the server and show additional errors that may not be visible using systemctl

warren · April 8, 2020 at 14:01

Thanks Tobias. Did a complete fresh install and ran through it again…..still the same. “sudo nguni -t” resolves in “command not found”. the nginx folder gets installed in /etc though. I suppose the crucial part happens after installation of nginx. Unlike in your description, it won’t start.
“systemctl status nginx.service” and journalctl -xe show

nginx.service: Failed at step EXEC spawning /usr/sbin/nginx: No such file or directory

which makes me wonder….

Warren · April 8, 2020 at 21:03

Got it solved
There’s, of course, no Apache running on a mint Raspbian Buster Lite – so there’ no interference as you described.
First, I installed the regular nginx for RPi according to this https://www.raspberrypi.org/documentation/remote-access/web-server/nginx.md and tested it successfully.
Then followed your instruction, but used just “sudo apt install libnginx-mod-rtmp” and all the rest of it.
Done. Up and running now 🙂

Thanks for the inspiration.
Stay healthy
w

    Tobias Hofmann · April 9, 2020 at 11:21

    Great to hear that it works now for you. Just wondering why apt did not select nginx for automatic installation in your case when you installed the rtmp mod.

Warren (again) · April 8, 2020 at 21:04

Got it solved
There’s, of course, no Apache running on a mint Raspbian Buster Lite – so there’ no interference as you described.
First, I installed the regular nginx for RPi according to this https://www.raspberrypi.org/documentation/remote-access/web-server/nginx.md and tested it successfully.
Then followed your instruction, but used just “sudo apt install libnginx-mod-rtmp” and all the rest of it.
Done. Up and running now 🙂

Thanks for the inspiration.
Stay healthy
w

Lee · May 24, 2020 at 09:37

Have you been able to get rtmp into html5 web page?

Xavier · May 30, 2020 at 17:59

Had the same problems with the installation on a fresh Raspi Buster. It’s actually necessary to install nginx first and then rtmp.
After that, all works very well

Marc · June 6, 2020 at 22:13

I didn’t think this would be so easy.

Thanks for showing us how it works.

Is there any way to change the key from “test” to something else?

    Tobias Hofmann · June 7, 2020 at 09:37

    Hi Marc,

    just change the key name to something else. The rtmp module will take the passed on key and add it to the /live/ URL.

Mowgli · June 15, 2020 at 13:19

I’ve got as far as having nginx running on my Pi and OBS sending video to it from a different computer on the same network. Now, the video I’m getting on the Pi viewed using VLC is unusable. There is a considerable lag which in itself is not the end of the world but I’m getting about one frame every 30 secs, I don’t think this qualifies as video! I really don’t know where the problem might be or what to do about it. The thing is that this is not even the set-up that I’m trying to get going. I want to be able to stream to the Pi from outside my network but after seeing the current performance I’m questioning whether this is a worthwhile pursuit!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.