In this article, we will discuss how to setup a streaming server with NGINX RTMP module.
If you are looking to buy a streaming server, we have 10gbps dedicated servers to boost your streaming. We provision servers quickly, affordably, and reliably.
An HLS Streaming Server is one of the most popular protocols for streaming videos. HLS is an adaptive streaming platform that allows you to stream media content to the best viewing experience, customized to the user's device and network conditions.
HLS and RTMP can be easily integrated with the Nginx web server using the Nginx RTMP module. In this tutorial, we'll show you how to setup an HLS live streaming server on Ubuntu.
Here we will show you how to configure HLS live streaming server on Ubuntu. It is easy to integrate with the Nginx web server.
Let's get to know about Nginx RTMP.
Nginx RTMP is an Nginx module that allows you to add streaming RTMP and HLS to your media server. The RTMP and HLS modules were previously separate Nginx modules, but now they can all be integrated as a single module to Nginx.
Prerequisites:
HostnExtra 10gbps dedicated servers with Ubuntu OS installed.
Let's get started with the installation
Step 1: Login via SSH to the server:
Login as root or a user with sudo access on the server.
Step2: Keep server up-to-date:
Always keep the server updated and if you the server is new, you should consider updating the system software:
apt-get update -y
apt-get upgrade -y
Step 3: Download required software
Start by updating the apt repository:
- apt-get install -y git build-essential ffmpeg libpcre3 libpcre3-dev libssl-dev zlib1g-dev
Step 3: Clone Module
Step 4: Download Nginx
Copy the latest download link from the Nginx website and decompress the files:
- wget http://nginx.org/download/nginx-1.17.6.tar.gz
- tar -xf nginx-1.17.6.tar.gz
- cd nginx-1.17.6
Step 5: Configure Nginx
- ./configure --prefix=/usr/local/nginx --with-http_ssl_module --add-module=../nginx-rtmp-module
- make -j 1
- make install
Step 6: Configure Nginx
rm /usr/local/nginx/conf/nginx.conf
vim /usr/local/nginx/conf/nginx.conf
Copy the following contents into the file and save it:
worker_processes auto;
events {
worker_connections 1024;
}
rtmp {
server {
listen 1935; # Listen on standard RTMP port
chunk_size 4000;
application show {
live on;
hls on;
hls_path /mnt/hls/;
hls_fragment 3;
hls_playlist_length 60;
deny play all;
}
}
}
http {
sendfile off;
tcp_nopush on;
directio 512;
default_type application/octet-stream;
server {
listen 8080;
location / {
add_header 'Cache-Control' 'no-cache';
add_header 'Access-Control-Allow-Origin' '*' always;
add_header 'Access-Control-Expose-Headers' 'Content-Length';
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/;
}
}
}
Step 7: Start Nginx
Start Nginx
- /usr/local/nginx/sbin/nginx
Step 8: Start Streaming
This server can stream from a variety of sources including a static file, webcam, etc.
We previously installed ffmpeg. We'll start streaming example-vid.mp4 to our http://localhost/show/stream
- ffmpeg -re -i example-vid.mp4 -vcodec libx264 -vprofile baseline -g 30 -acodec aac -strict -2 -f flv rtmp://localhost/show/stream
Step 9: Integrate into Player
The stream can now be integrated into a javascript HLS player as per your requirements.
We have successfully setup a streaming server with NGINX RTMP module.
Top comments (0)