NGINX / Server Setup

Install NGINX RTMP module in CentOS/RHEL or Amazon Linux

by ,


We have by far the largest RPM repository with dynamic stable NGINX modules and VMODs for Varnish 4.1 and 6.0 LTS. If you want to install NGINX, Varnish, and lots of useful modules for them, this is your one-stop repository to get all performance-related software.
You have to maintain an active subscription in order to be able to use the repository!

What is NGINX RTMP module

The RTMP module for NGINX provides HLS and MPEG-DASH live streaming capabilities for those who want a lightweight solution based on the HTTP protocol. The stream is published in the MPEG-TS format over HTTP. This makes it possible to use all the power and flexibility of nginx HTTP configurations including SSL, access control, logging, request limiting, etc. MPEG-TS is a widely adopted, well known and well-documented streaming format.

You can use our repository to easily install the RPM package for the dynamic RTMP module for NGINX.
The dynamic module is compatible with the latest stable/mainline NGINX for CentOS/RHEL or Amazon Linux.

Step 1. Add GetPageSpeed extras YUM repository

Run the following command to add our repository:

sudo yum -y install https://extras.getpagespeed.com/release-latest.rpm

Step 2. Install NGINX and RTMP module

Then, all you have to do to install NGINX with RTMP module:

sudo yum -y install nginx nginx-module-rtmp

Follow the installation prompt to import GPG public key that is used for verifying packages.

Step 3. Enable RTMP support in NGINX

Once you have installed the RTMP NGINX module package, it must be enabled.
You may want to simply follow the installer’s suggestion:

----------------------------------------------------------------------

The nginx-module-rtmp has been installed.
To enable this module, add the following to /etc/nginx/nginx.conf
and reload nginx:

    load_module modules/ngx_rtmp_module.so;

Please refer to the module documentation for further details:
https://github.com/arut/nginx-rtmp-module

----------------------------------------------------------------------

Doing so will enable NGINX to load the module and enable its directives.

Configure RTMP module

There are various ways you can use the module.

Simple Video-on-Demand

rtmp {
    server {
        listen 1935;
        application vod {
            play /var/flvs;
        }
    }
}

Forward live broadcast service

rtmp {
 server{
     listen 1935;
     chunk_size 4096;

     application live {
           live on;
           record off;
           push rtmp://live.twitch.tv/app/[streamkeyfromtwitch];
           push rtmp://a.rtmp.youtube.com/live2/[streamkeyfromyoutube];
          }
    }
}  

Re-translate remote stream with HLS support

rtmp {
    server {
        listen 1935;
        application tv {
            live on;

            hls on;
            hls_path /tmp/tv2;
            hls_fragment 15s;

            pull rtmp://tv2.example.com:443/root/new name=tv2;
        }
    }
}

http {
    server {
        listen 80;
        location /tv2 {
            alias /tmp/tv2;
        }
    }
}

Stream your X screen through RTMP

ffmpeg -f x11grab -follow_mouse centered -r 25 -s cif -i :0.0 -f flv rtmp://localhost/myapp/screen

For more details and examples, refer to the NGINX RTMP module project.

Feels like something is still missing? Then continue reading on how to install PageSpeed module in NGINX 🙂

Leave a Reply

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