In this article you will learn how to setup NGINX RTMP Server and Re-stream to Twitch, YouTube, Facebook or any other streaming platform. Step by step. Bonus: Configure VOD, Re-translate remote stream with HLS support
Time needed: 20 minutes
How to install nginx-rtmp-module on Ubuntu
- Install System Dependencies
Install all necessary dependencies for building NGINX and RTMP module
- Compile and Build NGINX Server
Download sources, unpack, compile NGINX with nginx-rtmp-module and http_ssl modules
- Edit NGINX configuration
Edit NGINX configuration and add RTMP section for enable RTMP live service, start server
- Publish RTMP Stream to NGINX
Publish RTMP Stream to NGINX server live location
Install System Dependencies
First update your Linux and install all necessary dependencies:
# apt-get -y update
# apt-get install build-essential libpcre3 libpcre3-dev libssl-dev zlibc zlib1g zlib1g-dev
Download NGINX most recent version (in our case it’s nginx-1.18.0).
# wget http://nginx.org/download/nginx-1.18.0.tar.gz
And unpack it:
# tar xvfz nginx-1.18.0.tar.gz
Go to NGINX sources directory
# cd nginx-1.18.0
Clone the NGINX RTMP Module from GitHub
# git clone https://github.com/arut/nginx-rtmp-module.git
COMPILE AND BUILD NGINX
Compile NGINX
Now lets compile NGINX with nginx-rtmp-module and http_ssl modules:
# ./configure --with-http_ssl_module --add-module=nginx-rtmp-module/
Build NGINX and Install NGINX
# make # make install
Start NGINX
To start NGINX server run command:
# /usr/local/nginx/sbin/nginx
Simple Streaming Server
Edit NGINX configuration file with any text editor:
# vim /usr/local/nginx/conf/nginx.conf
and add RTMP section for enable RTMP live service with listen on standard 1935 port:
rtmp { server { listen 1935; # Listen on standard RTMP port chunk_size 4096; # Enable simple RTMP live broadcast service application live { live on; record off; } } }
Publish RTMP Stream to NGINX and re-stream RTMP
Edit NGINX configuration file: /usr/local/nginx/conf/nginx.conf:
rtmp { server{ listen 1935; chunk_size 4096; #Enable live broadcast service application live { live on; record off; #Push, restream RTMP push rtmp://live.twitch.tv/app/YOUR_TWITCH_KEY; push rtmp://a.rtmp.youtube.com/live2/YOUR_YOUTUBE_KEY; } } }
Simple VOD Server (Video on Demand)
Where /var/files – your FLV files location
rtmp {
server {
listen 1935;
application vod {
play /var/files;
}
}
}
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;
}
}
}
Publish RTMP Stream to NGINX and Play
You can publish RTMP stream like: rtmp://SERVER_IP/live/stream_key
To play published stream with (VLC for example) player also use same address: rtmp://SERVER_IP/live/stream_key
Conclusion
This quick tutorial explained how to setup NGINX with RTMP module and re-stream to various streaming platforms like YouTube, Twitch, Facebook etc…. Aslo how to configure VOD server and Re-translate remote stream with HLS support
Discuss article in ArsTech Forum
Start the discussion at forum.arstech.net