How to Install an Nginx RTMP Server in Ubuntu 22.04

nginx rtmp splash

In this tutorial, you will learn how to install the Nginx web server and enable the RTMP (Real-Time Messaging Protocol) module on any Ubuntu-based distribution. The RTMP protocol is a robust and efficient means of transmitting live video streams from your computer to the internet. This makes it an indispensable tool for content creators and streamers. With this tutorial, you can master the installation and configuration of Nginx with the RTMP module. This will allow you to broadcast your live video streams with ease.

Nginx is an open-source web server that is known for its efficiency, scalability, and reliability. It is widely used by web developers and system administrators to serve dynamic web content, reverse proxy, load balance, and cache HTTP requests. The Nginx RTMP module supports live streaming, making it an all-in-one solution for web developers and content creators.

RTMP is widely used by video streaming services such as YouTube, Twitch, and Facebook Live. With Nginx and the RTMP module, you can create your own video streaming service or broadcast your content on existing platforms. Whether you are a web developer looking to add live streaming to your website or a content creator looking to broadcast your content to a global audience. This tutorial is an excellent starting point to get you up and running with Nginx and the RTMP module.

Sponsored Products

Update and Upgrade Ubuntu

update and upgrade ubuntu

The first thing you will need to do is update and upgrade Ubuntu. You can do this with the following apt command.

sudo apt update && sudo apt upgrade

Install Nginx Web Server

install nginx web server

Next install nginx using apt.

sudo apt install nginx

Enable the Ubuntu Universe Repository

enable universal repository

We will now need to enable the Ubuntu Universe Repository. It is usually enabled by default but it is a good idea to verify. This will allow us to install the Nginx rtmp module.

sudo add-apt-repository universe

Install the Nginx RTMP Module

install nginx rtmp module

After you have enabled the repository, install the Nginx RTMP module using the command below. This will allow us to stream RTMP video using the Nginx web server.

sudo apt install libnginx-mod-rtmp

Open the Nginx Config File

open nginx config

Now we will need to make a few configuration changes in the nginx config file. Open it using the nano text editor.

sudo nano /etc/nginx/nginx.conf

Add Lines to Config

edit nginx config

Once you have opened the config file, scroll to the bottom and add the following lines. After adding them, save and close the file.

rtmp {
	server {
		listen 1935;
		chunk_size 4096;

		application live {
			live on;
			record off;
		}
	}
}

Restart Nginx Web Server

restart nginx

The last step of the installation process is to restart Nginx. Do this using the following systemctl command.

sudo systemctl restart nginx

Create a Test RTMP Stream with OBS

At this point we have finished the installation and configuration of a RTMP streaming server using Nginx. We now need to test the server. In this article I will be using OBS Studio to demonstrate the test stream. Below you will see instructions for installing OBS on both Windows and Linux. Choose the option that matches the OS of the system you will be streaming from.

Install OBS Studio (Ubuntu)

install obs studio ubuntu

Run the following command to install OBS Studio on Ubuntu.

sudo apt install obs-studio

Install OBS Studio (Windows)

To install OBS on Windows download it from the link below. Then launch the installer and follow the prompts.

Download OBS Studio

Open OBS Studio

open obs

After you have finished installing OBS Studio we can test the stream. Launch the program to get started.

Add a New Source

add a new source obs

Next click on the “+” button in the lower left to add a new source. I will be using the screen capture for this example, however feel free to use any source.

Choose Display

choose a display obs

Next it will ask which screen you would like to use. Generally it is on the correct option by default, but change it if it looks incorrect. Then click on the “OK” button.

Open OBS Settings Menu

open settings menu obs

Then we will need to open the OBS settings menu. Click on “Settings” in the lower right hand corner.

Stream to a Custom RTMP Server with OBS

stream to a custom rtmp server obs

Once the settings menu opens click on the “Stream” tab on the left hand side. Once you are on the tab change all three fields highlighted in red. Change the service drop down to “Custom…”, the Server to “rtmp://NGINX_SERVER_IP/live”, and the Stream Key to “test”. Then click on “OK” to save the changes.

Start the Test Stream

start streaming obs

After saving your streaming settings click on the “Start Streaming” button to begin the RTMP stream.

Open a Network Stream in VLC

open network stream vlc

Now we will test the RTMP stream using VLC Media Player. Launch the program then navigate to the “Media” tab in the top bar. Then click on “Open Network Stream…”.

Enter Network Stream URL

enter network url vlc

Enter the following into the box highlighted in red replacing “localhost” with your Nginx servers IP address. Then click on the “Play” button to start watching the stream.

rtmp://NGINX_SERVER_IP/live/test

Verify the RTMP Stream

verify rtmp stream

Verify that you can see your OBS stream. If you are able to see it then you have successfully streamed to a Nginx RTMP server using OBS Studio.

Questions?

If you have any questions or comments feel free to leave them below.

Related Resources

View our 5 Reasons to Switch from Windows 10 to Linux.

Learn How to Install Ubuntu Server 22.04 [Step by Step].

Check out our How to Easily Create a Bootable Linux USB Drive using Rufus article.

View our How to Setup an SFTP Server on Ubuntu 22.04 using OpenSSH tutorial.

Learn more cool things in Windows with our Linux Tutorials.

View all of our available online tools and converters at Formatswap.com.

4 thoughts on “How to Install an Nginx RTMP Server in Ubuntu 22.04

    1. Here is an example of the config changes you would need to make to enable m3u8.

      rtmp {
      server {
      listen 1935; // RTMP server port

      application myapp {
      live on;
      hls on;
      hls_path /path/to/hls/;
      hls_fragment 2s; // Set the duration of each HLS segment
      hls_playlist_length 6s; // Set the duration of the HLS playlist

      # Additional RTMP configuration settings if needed

      # Specify different video resolutions and bitrates if desired
      # exec ffmpeg -i rtmp://localhost/myapp/$name -c:v libx264 -preset veryfast -c:a aac -b:v 500k -b:a 128k -f flv rtmp://localhost/myapp/$name_500k;
      }

      # Additional application blocks for different streaming applications if needed

      # server-level RTMP configuration settings if needed
      }

      # Additional server blocks for multiple RTMP servers if needed
      }

      http {
      server {
      listen 80; // HTTP server port

      location /hls {
      types {
      application/vnd.apple.mpegurl m3u8;
      video/mp2t ts;
      }
      root /path/to/;
      add_header Cache-Control no-cache; // Recommended for HLS streaming

      # Additional HTTP configuration settings if needed
      }

      # Additional server-level HTTP configuration settings if needed
      }

      # Additional server blocks for multiple HTTP servers if needed
      }

      Once the NGINX RTMP server is running and configured, you can obtain the M3U8 URL by combining the server’s URL or IP address with the path specified in the RTMP configuration. For example, if your NGINX server is running on example.com and you defined the hls_path as /path/to/hls/, the M3U8 URL might be http://example.com/path/to/hls/stream.m3u8

      Hope this helps.

  1. Hey, thank you for your tutorials, but I have some problems related to receiving the video in other device. After setting and watching the video via VLC on my local ubuntu machine, I tried to watch it with another laptop in the same WIFI network, but when I inputed the url on the VLC player, it didn’t work and poped up error, unable to access. So do I need to add something in the configuration to allow the server to stream and be accessible in another device? Thank you so much!

    1. Hi Oliver, I am glad you enjoyed the tutorial. Here are some steps you could try to resolve the issue. It is most likely a firewall issue.

      1. Verify Connectivity: Ensure that the NGINX RTMP server is reachable from the other laptop on the same Wi-Fi network. You can test this by pinging the server’s IP address from the laptop.

      2. Check Firewall Settings: Confirm that the firewall on the NGINX server allows incoming connections on the RTMP port (default: 1935). Additionally, make sure that any firewalls on the laptop or network router are not blocking access to the NGINX server.

      3. Adjust Network Configuration: Check the network configuration on the NGINX server to ensure it is set up correctly. Verify that the server’s IP address and subnet mask are properly configured for the Wi-Fi network.

      4. Verify URL Format: Double-check the URL you are using in VLC on the other laptop. It should be in the format `rtmp:///`. Ensure that you have entered the correct IP address or hostname of the NGINX server and the appropriate application name as configured in your NGINX RTMP server.

      5. Test with Different Devices: If possible, try streaming from other devices on the same Wi-Fi network to see if the issue is specific to the laptop or VLC player. This can help identify whether the problem lies with the NGINX server or the client device.

      6. Monitor NGINX Logs: Check the NGINX logs for any error messages or warnings related to the incoming connection attempts. The log file is usually located at `/var/log/nginx/error.log`. This can provide insights into the cause of the connection issues.

      7. Check Network Isolation: If the NGINX server and the other laptop are on different network segments or isolated subnets, ensure that there are no network configuration restrictions or firewall rules preventing access between them.

      By following these troubleshooting steps, you should be able to identify and resolve the issue preventing the NGINX RTMP server from being accessible and streaming video on other devices within the same Wi-Fi network.

Leave a Reply

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