• Contact
  • Contact Us
  • Disclamer
  • Home 1
  • Home 2
  • Home 3
  • Privacy Policy
Tuesday, June 24, 2025
How VPS - How to use/setup VPS
  • Login
  • Home
  • Management guides
    • Web servers software
      • Directadmin
      • Hocvps Script
      • Centmin Mod
      • CWP
      • Kloxo-MR
      • Plesk
    • Control Panels
    • Securing VPS/Servers
      • SSL Certificates
      • Upgrading
      • Authentication
  • Operating System
    • CentOS
    • Fedora
    • Debian
    • Linux
    • Arch
    • BSD
    • CoreOS
  • Reviews
  • Coupon
    • Domain Coupon
    • Hosting Coupon
No Result
View All Result
  • Home
  • Management guides
    • Web servers software
      • Directadmin
      • Hocvps Script
      • Centmin Mod
      • CWP
      • Kloxo-MR
      • Plesk
    • Control Panels
    • Securing VPS/Servers
      • SSL Certificates
      • Upgrading
      • Authentication
  • Operating System
    • CentOS
    • Fedora
    • Debian
    • Linux
    • Arch
    • BSD
    • CoreOS
  • Reviews
  • Coupon
    • Domain Coupon
    • Hosting Coupon
No Result
View All Result
How VPS - How to use/setup VPS
No Result
View All Result
Home Operating System CentOS

Setup Nginx-RTMP on CentOS 7

How VPS by How VPS
October 1, 2019
in CentOS
0
0
SHARES
40
VIEWS
Share on FacebookShare on Twitter

Contents

  1. Using a Different System?
  2. Installing Nginx and Nginx-RTMP
  3. Installing FFmpeg
  4. Configuring Nginx-RTMP and FFmpeg
  5. Security Note
  6. Configuring Software to Work with Nginx-RTMP
  7. Want to contribute?

Using a Different System?

  • Setup Nginx-RTMP on Ubuntu 14.04

Are we missing a guide for your target system? Request one, or submit your own!


RTMP is great for serving live content. When RTMP is paired with FFmpeg, streams can be converted into various qualities. Vultr is great for these applications as they provide fast and dedicated CPU performance. Vultr’s global network also ensures that you can deliver high-quality live content with minimal delay. Let’s get started!

Installing Nginx and Nginx-RTMP

Install the tools required to compile Nginx and Nginx-RTMP from source.

sudo yum install pcre pcre-devel openssl openssl-devel zlib zlib-devel -y

Make a working directory and switch to it.

mkdir ~/working
cd ~/working

Download the Nginx and Nginx-RTMP sources.

wget http://nginx.org/download/nginx-1.9.7.tar.gz
wget https://github.com/arut/nginx-rtmp-module/archive/master.zip

Install the unzip package.

sudo yum install unzip

Extract the Nginx and Nginx-RTMP source.

tar -xvf nginx-1.9.7.tar.gz
unzip v1.2.1.zip

Switch to the Nginx directory.

cd nginx-1.9.7

Add modules to compile into Nginx. Nginx-RTMP is included.

./configure --add-module=../nginx-rtmp-module-1.2.1/

Compile and install Nginx with Nginx-RTMP.

make
sudo make install

Create a SystemD unit file for Nginx.

sudo nano /usr/lib/systemd/system/nginx.service

Populate the file with the following content.

[Unit]
Description=nginx - high performance web server
Documentation=https://nginx.org/en/docs/
After=network-online.target remote-fs.target nss-lookup.target
Wants=network-online.target

[Service]
Type=forking
PIDFile=/var/run/nginx.pid
ExecStartPre=/usr/sbin/nginx -t -c /etc/nginx/nginx.conf
ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID

[Install]
WantedBy=multi-user.target

Start and enable the Nginx service.

sudo systemctl start nginx.service

Tell SystemD to start Nginx services automatically at boot.

systemctl enable nginx.service

Installing FFmpeg

Install epel-release and update the system.

sudo yum install epel-release -y
sudo yum update -y
sudo shutdown -r now

Install the Nux repository.

sudo rpm --import http://li.nux.ro/download/nux/RPM-GPG-KEY-nux.ro
sudo rpm -Uvh http://li.nux.ro/download/nux/dextop/el7/x86_64/nux-dextop-release-0-5.el7.nux.noarch.rpm

Install FFmpeg and its development packages.

sudo yum install ffmpeg ffmpeg-devel -y

Configuring Nginx-RTMP and FFmpeg

Open the Nginx configuration file.

sudo nano /usr/local/nginx/conf/nginx.conf

Append the following to the configuration.

    rtmp {
        server {
            listen 1935;
            chunk_size 4096;

            application live {
                    live on;
                    record off;
                    exec ffmpeg -i rtmp://localhost/live/$name -threads 1 -c:v libx264 -profile:v baseline -b:v 350K -s 640x360 -f flv -c:a aac -ac 1 -strict -2 -b:a 56k rtmp://localhost/live360p/$name;
            }
            application live360p {
                    live on;
                    record off;
        }
    }
}

After you’ve added that configuration text, you can customize settings such a video bitrate, audio bitrate, and resolution. These changes will only be applied to the lower quality stream. To add more qualities, copy and paste the exec FFmpeg line and change the settings. You’ll also need to create a new application. You can do this by copying and pasting the live360 example that has been included. Don’t forget to update the exec FFmpeg line with the address of the new application. You can do this by changing the final RTMP address in the exec FFmpeg line.

Note: Changing the value after -b:v will change the video bitrate. This is measured in kilobits per second. Changing the value after -b:a will change the audio bitrate. This is measured in kilobits per second. Changing the value after -s will change the resolution.

Save the file by pressing CTRL + X.

Restart Nginx.

sudo service nginx restart

Note: For best performance, each stream being converted should have its own CPU core. For example, if two qualities, 360P and 480P, are being created from a 720P stream, a Vultr instance with at least two CPU cores should be used.

Security Note

If you’re using a firewall, you’ll need to make sure TCP 1935 is allowed.

The current configuration allows anyone to stream to your server. We can fix this by only giving certain IP addresses the publish permission. Open the Nginx configuration.

sudo nano /usr/local/nginx/conf/nginx.conf

Look for the following lines.

live on;
record off;

Add the following to each set of the above lines. Change 0.0.0.0 to your actual IP address.

allow publish 127.0.0.1;
allow publish 0.0.0.0;
deny publish all;

The configuration will now look something like the following.

rtmp {
    server {
        listen 1935;
        chunk_size 4096;

        application live {
                live on;
                record off;
                allow publish 127.0.0.1;
                allow publish 0.0.0.0;
                deny publish all;
                exec ffmpeg -i rtmp://localhost/live/$name -threads 1 -c:v libx264 -profile:v baseline -b:v 350K -s 640x360 -f flv -c:a aac -ac 1 -strict -2 -b:a 56k rtmp://localhost/live360p/$name;
        }
        application live360p {
                live on;
                record off;
                allow publish 127.0.0.1;
                allow publish 0.0.0.0;
                deny publish all;
        }
    }
}

Save the file by pressing CTRL + X.

Restart Nginx.

sudo service nginx restart

Configuring Software to Work with Nginx-RTMP

Streaming applications typically have two fields for connection information. The first field is usually for the server information and the second field is usually for the stream name or key. The information that you should place into each field is listed. The stream name or key can be set to anything.

Field 1: rtmp://your.vultr.ip/live/
Field 2: stream-key-you-set

To view the streams, open the following links in a player supporting RTMP.

rtmp://your.vultr.ip/live/stream-key-you-set
rtmp://your.vultr.ip/live360p/stream-key-you-set

Want to contribute?

You could earn up to $300 by adding new articles

Submit your article
Suggest an update
Request an article
Previous Post

Installing Pagekit CMS on CentOS 7

Next Post

How to Install Mautic on CentOS 7

Next Post

How to Install Mautic on CentOS 7

Leave a Reply Cancel reply

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

No Result
View All Result

Recent Post

Install Imagemagick on CentOS
CentOS

Install Imagemagick on CentOS

by How VPS
June 28, 2023
0

This is how I installed Imagemagick on a vanilla CentOS server Start off by installing the prerequisites yum install php-pear...

Read more
how to Check phpinfo

How to Check phpinfo of Hosting or VPS?

June 28, 2023
Failed to download metadata for repo 'appstream' on Centos 8

How to fix error: Failed to download metadata for repo ‘appstream’ on Centos 8

February 25, 2022
How to Fix MySQL Error "Plugin 'InnoDB' registration as a STORAGE ENGINE failed"?

How to Fix MySQL Error “Plugin ‘InnoDB’ registration as a STORAGE ENGINE failed”?

November 17, 2020
How to optimize Mysql or MariaDB

How to optimize Mysql or MariaDB

November 3, 2020

Recent News

  • Install Imagemagick on CentOS
  • How to Check phpinfo of Hosting or VPS?
  • How to fix error: Failed to download metadata for repo ‘appstream’ on Centos 8

Category

  • Arch
  • Authentication
  • Backups
  • BSD
  • Centmin Mod
  • CentOS
  • Control Panels
  • CoreOS
  • CWP
  • Debian
  • Directadmin
  • Encryption
  • Fedora
  • Firewalls
  • Hocvps Script
  • Hosting providers
  • Kloxo-MR
  • Linux
  • Mitigations
  • Operating System
  • Plesk
  • Reviews
  • Securing VPS/Servers
  • Security Patches
  • SSL Certificates
  • Uncategorized
  • Upgrading
  • VPS/Servers management guides
  • Vulnerability Detection
  • Web servers software
  • Webhosting Control Panel
  • About
  • Advertise
  • Careers
  • Contact

© 2025 JNews - Premium WordPress news & magazine theme by Jegtheme.

No Result
View All Result
  • Home
  • Management guides
    • Web servers software
      • Directadmin
      • Hocvps Script
      • Centmin Mod
      • CWP
      • Kloxo-MR
      • Plesk
    • Control Panels
    • Securing VPS/Servers
      • SSL Certificates
      • Upgrading
      • Authentication
  • Operating System
    • CentOS
    • Fedora
    • Debian
    • Linux
    • Arch
    • BSD
    • CoreOS
  • Reviews
  • Coupon
    • Domain Coupon
    • Hosting Coupon

© 2025 JNews - Premium WordPress news & magazine theme by Jegtheme.

Welcome Back!

Login to your account below

Forgotten Password?

Retrieve your password

Please enter your username or email address to reset your password.

Log In