fbpx

Server Setup

How to install the RTMP NGINX module in Plesk for CentOS/RHEL 7 or 8

by , , revisited on


We have by far the largest RPM repository with NGINX module packages and VMODs for Varnish. If you want to install NGINX, Varnish, and lots of useful performance/security software with smooth yum upgrades for production use, this is the repository for you.
Active subscription is required.

What is the 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 the RTMP module:

sudo yum -y install sw-nginx-module-rtmp

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:

plesk sbin nginx_modules_ctl --enable rtmp

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

Configure RTMP module

Connect to your server via SSH, create file /etc/nginx/modules.conf.d/zzz_custom.conf and place the relevant RTMP directives there.
This file guarantees that your configuration is preserved upon upgrades.

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 documentation.

SELinux notes

The module pulls in an additional SELinux policy which allows NGINX to bind on RTMP port 1935.
So the module is fully compatible with SELinux.

Leave a Reply

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

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

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