Download as pdf or txt
Download as pdf or txt
You are on page 1of 20

14/3/2021 How to Install Nginx with RTMP Module on CentOS 7

Log in or Sign up

Tutorials Tags Forums Linux Commands Subscribe ISPConfig News

 Tutorial search 

Home How to Install Nginx with RTMP Module on CentOS 7

How to Install Nginx with RTMP Module on CentOS


7

RTMP (Real Time Messaging On this page


Protocol) is a high-
performance protocol for Prerequisites
transmission of data, audio, What we will do?
and video over the internet Step 1 - Install Dependencies
between flash-based platform Step 2 - Download Nginx with Additional Package
technologies. Originally and RTMP Module
developed by Macromedia, and Step 3 - Compile Nginx and Install from Source
now owned by Adobe. Step 4 - Configure Nginx as a Service
Step 5 - Configure Nginx RTMP Module
Step 6 - Setup First RTMP Live Stream
Step 7 - Testing
Video On Demand Stream
Live Stream using OBS (Open Broadcaster
Software)
Reference

Nginx RTMP is a nginx-based media streamer with RTMP, HLS, and MPEG-DASH live
streaming. Nginx RTMP module has lot of features, including H264/AAC support, HTTP
callback support, HTTP control module for recording the audio/video etc.
x
In this tutorial, I will show you how to install and configure the Nginx web server with the
RTMP module. We will be using the latest CentOS 7 server, and this guide will include the
configuration of nginx and rtmp module and creating RTMP live stream and video on
demand.

https://www.howtoforge.com/tutorial/how-to-install-nginx-with-rtmp-module-on-centos/ 1/20
14/3/2021 How to Install Nginx with RTMP Module on CentOS 7

x
Prerequisites
CentOS 7 Server
Root privileges

What we will do?


Install Dependencies
Download Nginx with Additional Package and RTMP Module
Compile Nginx and Install from Source
Configure Nginx as a Service
Configure Nginx RTMP Module
Setup First RTMP Live Stream
Testing

Step 1 - Install Dependencies

In this tutorial, we will build the Nginx web server from source. We need to install all
packages dependencies needed, including development tools, EPEL repository, and other
packages.

Install CentOS 'Development Tools'.

sudo yum -y groupinstall 'Development Tools'

Add the EPEL repository.

Centos 7 RTMP Server Free Windows Downloads Free Tutorial Courses

sudo yum -y install epel-release

Install Nginx dependencies.

sudo yum install -y wget git unzip perl perl-devel perl-ExtUtils-Embed


libxslt libxslt-devel libxml2 libxml2-devel gd gd-devel pcre-devel GeoI
P GeoIP-devel

Wait for all packages installed.

https://www.howtoforge.com/tutorial/how-to-install-nginx-with-rtmp-module-on-centos/ 2/20
14/3/2021 How to Install Nginx with RTMP Module on CentOS 7

Step 2 - Download Nginx with Additional Package and RTMP


Module

In this step, we will download nginx source code with the additional dependencies including
pcre, zlib, and the OpenSSL.

Go to the '/usr/local/src' directory.

cd /usr/local/src

Download Nginx 1.14.0 and extract it.

wget https://nginx.org/download/nginx-1.14.0.tar.gz
tar -xzvf nginx-1.14.0.tar.gz
x

Download the pcre package and extract it.

wget https://ftp.pcre.org/pub/pcre/pcre-8.42.zip
unzip pcre-8.42.zip
https://www.howtoforge.com/tutorial/how-to-install-nginx-with-rtmp-module-on-centos/ 3/20
14/3/2021 How to Install Nginx with RTMP Module on CentOS 7

Download the zlib package and extract it.

wget https://www.zlib.net/zlib-1.2.11.tar.gz
tar -xzvf zlib-1.2.11.tar.gz

Download the OpenSSL package and extract it.

wget https://www.openssl.org/source/openssl-1.1.0h.tar.gz
tar -xzvf openssl-1.1.0h.tar.gz

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

git clone https://github.com/sergey-dryabzhinsky/nginx-rtmp-module.git

And remove all compressed tar.gz and .zip files.

rm -f *.tar.gz *.zip

Following are the directory details we have. x

ls -lah

https://www.howtoforge.com/tutorial/how-to-install-nginx-with-rtmp-module-on-centos/ 4/20
14/3/2021 How to Install Nginx with RTMP Module on CentOS 7

And we're ready to compile and install.

Step 3 - Compile Nginx and Install from Source

Go to the 'nginx-1.14.0' directory.

cd nginx-1.14.0/

Configure the nginx 1.14.0 using those parameters below.

./configure --prefix=/etc/nginx \
--sbin-path=/usr/sbin/nginx \
--modules-path=/usr/lib64/nginx/modules \
--conf-path=/etc/nginx/nginx.conf \
--error-log-path=/var/log/nginx/error.log \
--pid-path=/var/run/nginx.pid \
--lock-path=/var/run/nginx.lock \
--user=nginx \
--group=nginx \
--build=CentOS \
--builddir=nginx-1.14.0 \
--with-select_module \
--with-poll_module \
--with-threads \
--with-file-aio \
--with-http_ssl_module \
--with-http_v2_module \
--with-http_realip_module \
--with-http_addition_module \
--with-http_xslt_module=dynamic \
--with-http_image_filter_module=dynamic \
--with-http_geoip_module=dynamic \
--with-http_sub_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_mp4_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_auth_request_module \ x
--with-http_random_index_module \
--with-http_secure_link_module \
--with-http_degradation_module \
--with-http_slice_module \
--with-http_stub_status_module \
--http-log-path=/var/log/nginx/access.log \
--http-client-body-temp-path=/var/cache/nginx/client_temp \
https://www.howtoforge.com/tutorial/how-to-install-nginx-with-rtmp-module-on-centos/ 5/20
14/3/2021 How to Install Nginx with RTMP Module on CentOS 7
--http-proxy-temp-path=/var/cache/nginx/proxy_temp \ x
--http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp \
--http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp \
--http-scgi-temp-path=/var/cache/nginx/scgi_temp \
--with-mail=dynamic \
--with-mail_ssl_module \
--with-stream=dynamic \
--with-stream_ssl_module \
--with-stream_realip_module \
--with-stream_geoip_module=dynamic \
--with-stream_ssl_preread_module \
--with-compat \
--with-pcre=../pcre-8.42 \
--with-pcre-jit \
--with-zlib=../zlib-1.2.11 \
--with-openssl=../openssl-1.1.0h \
--with-openssl-opt=no-nextprotoneg \
--add-module=../nginx-rtmp-module \
--with-debug

Compile and install Nginx with RTMP module by running following commands.

sudo make
sudo make install

When the installation is complete, we need to create a new symlink module directory, create
a new nginx user and group, and create a new nginx cache directory.

Advertisement

https://www.howtoforge.com/tutorial/how-to-install-nginx-with-rtmp-module-on-centos/ 6/20
14/3/2021 How to Install Nginx with RTMP Module on CentOS 7

Create nginx symlink module to the '/etc/nginx' configuration directory.

sudo ln -s /usr/lib64/nginx/modules /etc/nginx/modules

Create a new 'nginx' system user and group.

sudo useradd -r -d /var/cache/nginx/ -s /sbin/nologin -U nginx

Now create a new Nginx cache directory '/var/cache/nginx' and change the owner of the
directory to 'nginx' user and group.

mkdir -p /var/cache/nginx/
chown -R nginx:nginx /var/cache/nginx/

Test nginx configuration and the installed nginx version.

nginx -t
nginx -V

And the following is the result.

https://www.howtoforge.com/tutorial/how-to-install-nginx-with-rtmp-module-on-centos/ 7/20
14/3/2021 How to Install Nginx with RTMP Module on CentOS 7

x
The Nginx web server has been installed on CentOS 7 with the RTMP Module enabled.

Step 4 - Configure Nginx as a Service

In this tutorial, we will be running nginx as a service and we need to create a new nginx
service file to the systemd service directory.

Go to the '/lib/systemd/system' directory and create a new 'nginx.service' file using vim.

cd /lib/systemd/system/
vim nginx.service

paste the configuration below.

[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

Save and exit.

Now reload the systemd system.

systemctl daemon-reload

Start the nginx service and enable it to launch everytime at system boot.

systemctl start nginx


systemctl enable nginx

The Nginx web server is up and running as a service on CentOS 7 system.

https://www.howtoforge.com/tutorial/how-to-install-nginx-with-rtmp-module-on-centos/ 8/20
14/3/2021 How to Install Nginx with RTMP Module on CentOS 7

Step 5 - Configure Nginx RTMP Module

In this step, we will create a new custom Nginx configuration for RTMP module.

Go to the '/etc/nginx' configuration directory and backup the original 'nginx.conf' file.

cd /etc/nginx/
mv nginx.conf nginx.conf.asli

Now create a custom configuration 'nginx.conf'.

vim nginx.conf

Paste Nginx RTMP configuration below.

worker_processes auto;
events {
worker_connections 1024;
}

# RTMP configuration
rtmp {
server {
listen 1935; # Listen on standard RTMP port
chunk_size 4000;

# Define the Application


application show {
live on;
# Turn on HLS
hls on;
hls_path /mnt/hls/;
hls_fragment 3;
hls_playlist_length 60;
# disable consuming the stream from nginx as rtmp
deny play all;
}

https://www.howtoforge.com/tutorial/how-to-install-nginx-with-rtmp-module-on-centos/ 9/20
14/3/2021 How to Install Nginx with RTMP Module on CentOS 7
} x
}

http {
sendfile off;
tcp_nopush on;
aio on;
directio 512;
default_type application/octet-stream;

server {
listen 8080;

location / {
# Disable cache
add_header 'Cache-Control' 'no-cache';

# CORS setup
add_header 'Access-Control-Allow-Origin' '*' always;
add_header 'Access-Control-Expose-Headers' 'Content-Length';

# allow CORS preflight requests


if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Max-Age' 1728000;
add_header 'Content-Type' 'text/plain charset=UTF-8';
add_header 'Content-Length' 0;
return 204;
}

types {
application/dash+xml mpd;
application/vnd.apple.mpegurl m3u8;
video/mp2t ts;
}

root /mnt/;
}
}
}

Save and exit.

Next, we need to create a new directory for the HLS configuration and we've defined the
web root directory is on the '/mnt' directory.

Create the 'hls' directory under the '/mnt' directory and change the owner of the directory to
the nginx user and group.

mkdir -p /mnt/hls
chown -R nginx:nginx /mnt/hls

Test the configuration and restart the nginx service.

nginx -t
systemctl restart nginx
https://www.howtoforge.com/tutorial/how-to-install-nginx-with-rtmp-module-on-centos/ 10/20
14/3/2021 How to Install Nginx with RTMP Module on CentOS 7

Step 6 - Setup First RTMP Live Stream

In this tutorial, we will create new RTMP stream video on demand using the mp4 videos on
the server, and create a new live RTMP stream that will be broadcasted from the local
computer using the OBS software.

Go to the '/etc/nginx' configuration directory and edit the 'nginx.conf' file.

cd /etc/nginx/
vim nginx.conf

Paste configurations below in to the 'rtmp { ... }' bracket.

# RTMP video on demand for mp4 files


application vod {
play /mnt/mp4s;
}

# RTMP stream using OBS


application stream {
live on;
}

Save and exit.

Now create a new directory 'mp4s' for storing all vod videos, and change the owner to the
nginx user group.

mkdir -p /mnt/mp4s
chown -R nginx:nginx /mnt/mp4s

Test nginx configuration and make sure there is no error, then restart the nginx service.

nginx -t
systemctl restart nginx

https://www.howtoforge.com/tutorial/how-to-install-nginx-with-rtmp-module-on-centos/ 11/20
14/3/2021 How to Install Nginx with RTMP Module on CentOS 7

x
Nginx configuration for the RTMP live stream and the vod stream has been completed.

Step 7 - Testing

Test RTMP live stream and vod stream using the VLC player.

Video On Demand Stream

Open the VLC app on your computer.

Click the 'File' menu choose the 'Open Network' option.

Now type the RTMP URL for our vod stream.

rtmp://192.168.1.10:1935/vod/file.mp4

Click the 'Open' button.

And the following are the results of the video stream.

https://www.howtoforge.com/tutorial/how-to-install-nginx-with-rtmp-module-on-centos/ 12/20
14/3/2021 How to Install Nginx with RTMP Module on CentOS 7

Live Stream using OBS (Open Broadcaster Software)

In this tutorial, we will test the RTMP live stream using the obs software, and the vlc player.

We will stream only the terminal window using the open broadcaster software, and try to
watch the RTMP live stream using the VLC player.

Following is my configuration for the obs software.

Open the VLC app on your computer.

Click the 'File' menu, choose the 'Open Network' option.

Now type the RTMP URL for our live stream.


https://www.howtoforge.com/tutorial/how-to-install-nginx-with-rtmp-module-on-centos/ 13/20
14/3/2021 How to Install Nginx with RTMP Module on CentOS 7

x
rtmp://192.168.1.10:1935/stream/

Click the 'Open' button.

And the following is the result of the live stream using open broadcaster through the nginx
rtmp module.

Installation of the Nginx web server with RTMP module on CentOS 7 has been completed
successfully.

Reference
https://github.com/sergey-dryabzhinsky/nginx-rtmp-module

About Muhammad Arul

https://www.howtoforge.com/tutorial/how-to-install-nginx-with-rtmp-module-on-centos/ 14/20
14/3/2021 How to Install Nginx with RTMP Module on CentOS 7

Muhammad Arul is a freelance system administrator and technical writer. He is working x


with Linux Environments for more than 5 years, an Open Source enthusiast and highly
motivated on Linux installation and troubleshooting. Mostly working with
RedHat/CentOS Linux and Ubuntu/Debian, Nginx and Apache web server, Proxmox,
Zimbra Administration, and Website Optimization. Currently learning about OpenStack
and Container Technology.

view as pdf | print

Share this page:

Suggested articles

16 Comment(s)
Add comment
Name * Email *

    

p

Submit comment
I'm not a robot
reCAPTCHA
Privacy - Terms

Comments

By: Doug Maupin Reply

This tutorial worked out great, but I would like know how would one add streamer authentication, while this
works it also allows anyone to stream on my setup i d like to be able to restrict access

By: MD Monowar Reply

https://www.howtoforge.com/tutorial/how-to-install-nginx-with-rtmp-module-on-centos/ 15/20
14/3/2021 How to Install Nginx with RTMP Module on CentOS 7

How to setup mobile live please help me x

By: JulioS Reply

Great post! How play the videos stored on /mnt/mp4s or /mnt/hls embeded in html?

By: neil Reply

I have done all right as what this article says, but still can't play video through vlc player.
By the way. The vlc player was installed on a Windows10 computer.
I try convert the rtmp stream to rtsp by using ffmpeg and it could successfuly parse the rtmp stream.

I don't know why my vlc player on windows os can't work. Could somebody help me.

By: Acacio Farias Brasil Reply

Hello, I wanted to know which VPS server to hire, I need to know what configuration I need to use with 2000
thousand people watching my video simultaneously, thanks for the tutorial.

By: richard Reply

Works like a charm, except how can I view the stream from an embedded player from the net. Works in VLC
just fine, but I want the live stream to be viewed by others on my website.

By: Hubert K Reply

I seem to have a problem streaming Live from OSB. Stream starts fine OSB connect to the server, stream
starts.
When I try using VLC to stream I just see the bar going back and forth, nothing happens, no errors on the
VLC side.
Any ides would be helpful.
Cheers,

Hubert

By: Litana Reply

plz help, im stuck in here systemctl enable nginx


Failed to execute operation: Bad message
what to do please ?
Thanks

By: Rob Reply

hello, I am looking to have someone build for me an HLS Streaming Server with NGINX so that I can do live
broadcasing on Roku IPTV.
I want to use my existing website to link the m3u8 link and run it through hoping that this may allow
unlimited viewers since i won't be saving any data. can anybody help? email me at trinityreseller@gmail.com

By: Barani Reply

Hi,
I would like to use this to try out and create tutorial with in contacts. Can I do so?

https://www.howtoforge.com/tutorial/how-to-install-nginx-with-rtmp-module-on-centos/ 16/20
14/3/2021 How to Install Nginx with RTMP Module on CentOS 7

By: petit Reply x


This is a great article. According to the tutorial, I successfully configured the nginx server. I would like to
translate your article to other forums. I wonder if it is OK? Thanks again?

By: Howtoforge Reply

I'm sorry, translation and republishing of HowtoForge articles is not permitted.

By: David123 Reply

Hello ,
I have donw excectlly as it say
didn't get any error
but it doesn't work ,
when I enter the
serverIP:8080 , I get nothing
ServerIP:1935 nothing
the service is up
sudo systemctl status nginx
? nginx.service - The nginx HTTP and reverse proxy server
Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)
Active: active (running) since Thu 2020-07-02 13:25:17 GMT; 32min ago

what could it be ?

Thanks,

By: till Reply

Do you use a firewall? Are the ports opened in the firewall?

By: Twitchy FPV Reply

Using CentOS 8 (Core) - All these steps work fanatstic except you now need to use nginx 1.15.0 instead of
1.14.0
wget https://nginx.org/download/nginx-1.15.0.tar.gztar -xzvf nginx-1.15.0.tar.gz

By: Eskimo Reply

hls fragmented files deleted after a while i upload them to the server! in fact, after 1 min the converted files
deletes on the server!
RTMP TEST WORKS FINE ON VLC.
here is my ffmpeg command:
ffmpeg -i /mnt/videos/myfile.mp4 /mnt/hls/myfile.m3u8
.......here is my hls config:# Define the Applicationapplication show {live on;# Turn on HLShls on;hls_path
/mnt/hls/;hls_cleanup off;hls_playlist_length 10y;hls_fragment 3;......Any Idea!TNX.

Home How to Install Nginx with RTMP Module on CentOS 7

https://www.howtoforge.com/tutorial/how-to-install-nginx-with-rtmp-module-on-centos/ 17/20
14/3/2021 How to Install Nginx with RTMP Module on CentOS 7

x
Sign up now!

 Tutorial Info

Author: Muhammad Arul


Tags: centos, linux, nginx

https://www.howtoforge.com/tutorial/how-to-install-nginx-with-rtmp-module-on-centos/ 18/20
14/3/2021 How to Install Nginx with RTMP Module on CentOS 7

 Share This Page

40.2k Followers

 Popular Tutorials

How to use grep to search for strings in files on


the shell

How do I edit files on the command line?

How to use the Linux ftp command to up- and


download files on the shell

The Perfect Server - Debian 10 (Buster) with


Apache, BIND, Dovecot, PureFTPD and ISPConfig
3.2

How to Setup APT Proxy on Ubuntu 20.04 LTS

How to Install and Use GVM Vulnerability Scanner


on Ubuntu 20.04

How to Setup Pritunl VPN Server on Ubuntu


20.04

How to Install Moodle with Nginx and Let's


Encrypt SSL on Ubuntu 20.04

How to Install Arkime Full Packet Capture tool on


Ubuntu 20.04

How to install Jenkins using a .war file on AWS


EC2 Ubuntu 20.04 instance

RTMP Receiver

RTMP IP Camera

https://www.howtoforge.com/tutorial/how-to-install-nginx-with-rtmp-module-on-centos/ 19/20
14/3/2021 How to Install Nginx with RTMP Module on CentOS 7

___ x

report this ad

Xenforo skin by Xenfocus Contribute Contact Help Imprint and Legal Notice

Howtoforge © projektfarm GmbH. Terms and Rules Privacy Policy

https://www.howtoforge.com/tutorial/how-to-install-nginx-with-rtmp-module-on-centos/ 20/20

You might also like