How to Install Nginx with RTMP Module on CentOS 7

By Sajid Qureshi, Alibaba Cloud Tech Share Author. Tech Share is Alibaba Cloud’s incentive program to encourage the sharing of technical knowledge and best practices within the cloud community.

RTMP (Real Time Messaging Protocol) is a high-performance protocol for streaming of data, audio, and video through the internet. In this guide, we will be installing Nginx with RTMP module which is a media streamer based on Nginx. It provides RTMP, HLS, and MPEG-DASH live streaming capabilities. Nginx RTMP module has a lot of features some of them are listed below:

  1. H264/AAC support
  2. Online transcoding with FFmpeg
  3. Running external programs on certain events (exec)
  4. HTTP control module for recording audio/video and dropping clients
  5. Advanced buffering techniques to keep memory allocations at a minimum level for faster streaming
  6. Stream relay support for distributed streaming: push & pull models

Prerequisites

  1. You must have Alibaba Cloud Elastic Compute Service (ECS) activated and verified your valid payment method. If you are a new user, you can get a free account in your Alibaba Cloud account. If you don’t know about how to set up your ECS instance, you can refer to this tutorial or quick-start guide. Your ECS instance must have at least 1GB RAM and 1 Core processor.
  2. A domain name registered from Alibaba Cloud. If you have already registered a domain from Alibaba Cloud or any other host, you can update its domain nameserver records.
  3. Root user

Update the System

It is recommended that you should install any new packages on a freshly updated server.

First of all, upgrade all the available packages and update the system using the following command.

Install Dependencies

We will install Nginx with RTMP module, but before that, you will need to install other dependencies required such as development tools, EPEL repository, and other packages.

Execute the following command to install development tools.

Now, add the EPEL repository to the CentOS 7 system.

Next, install Nginx dependencies and other required packages using the following command.

The above command will take some time, so hold on a bit.

Download Nginx with Additional Package

You have installed all the dependencies required, so let’s download and install Nginx source with some additional packages. First of all, change your current directory to ‘/usr/local/src’ using the following command.

Download Nginx using the following command.

Next, you will need to extract the above-downloaded file using the following command.

Next, you will need to download the pcre package execute the following to do so.

Extract the downloaded file.

Next, you will need to download the zlib package and extract it using the following commands.

Next, download the OpenSSL package and extract it.

Finally, clone the Nginx RTMP Module source code using git command.

Compile and Install Nginx

You have downloaded the Nginx with all the other required additional packages. So, let’s install and configure Nginx. To do so change your current directory to ‘nginx-1.14.0’.

Configure the nginx using these parameters below.

Install Nginx with RTMP module. Execute the following commands and they will do the job for you.

Once, the installation is complete create nginx symlink module to the ‘/etc/nginx’ configuration directory.

Next, you will need to create a new ‘nginx’ system user and group. Run the following command to do so.

Create a new directory using the following command.

Next, you will need to change the ownership rules for the directory.

Finally, you can verify and test this nginx installation using the following command.

Configure Nginx as a Service

In this guide, you will be using Nginx as a service so you will have to create a new nginx service file.

Change your current directory to ‘/lib/systemd/system’.

Now, create a new ‘nginx.service’ file using the following command.

Add the following content to the file.

Save the file and exit from the text editor.

Next, reload the systemd system using the following command.

Now, start the nginx service and enable it to launch at the boot time. Run following commands to do so.

Configure Nginx RTMP Module

Your Nginx server is active and running as a service on your CentOS 7 system. Now, you will have to create a new nginx configuration for RTMP module and to do so, change your current directory to the nginx configuration directory back up the original configuration file. Execute the following commands and they’ll do the job for you.

Create a new nginx configuration file using any text editor using the following command.

Add the following content to the file.

Save the file and exit from the text editor.

You will need to create a new directory for the HLS configuration using the following command.

Next, change the ownership rules for the same.

Finally, restart your nginx server to apply changes that we just configured using the following command.

Setup First RTMP Live Stream

All the required dependencies are installed and configured correctly now. Now, let’s create new RTMP stream video on demand using the mp4 videos on the server. You will need to edit the nginx configuration file to do so.

Add the following content into the ‘rtmp { … }’ bracket in the file.

Save the file and exit from the text editor.

To store all the videos data you will have to create a new directory using the following command.

Next, change the ownership rules for the directory to the nginx user group.

Finally, restart your nginx services using the following command.

Testing

You can test this installation and configuration by using RTMP live stream from the VLC media player.

Video On Demand Stream

  1. Open the VLC media player app on your computer.
  2. Click on the ‘File’ menu from the media library and select the Open Network option.
  3. Now enter the RTMP URL for our vod stream like this:
    rtmp://YourServerIP:1935/vod/file.mp4
    Replace YourServerIP with the actual IP address of your server.
  4. Finally, click on the Open button. You will get the Video Stream on your screen.

Conclusion

In this tutorial, you have learned how to install Nginx with the RTMP module. You also learned to high-performance streaming of video using this RTMP module. We hope now you have enough knowledge to work with this module.

Reference:https://www.alibabacloud.com/blog/how-to-install-nginx-with-rtmp-module-on-centos-7_594403?spm=a2c41.12532070.0.0

Written by

Follow me to keep abreast with the latest technology news, industry insights, and developer trends.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store