DEV Community

How To Setup Nginx For HLS Video Streaming On Centos 7

Samuyi on February 13, 2019

Introduction HLS stands for HTTP live streaming. It’s an HTTP based media streaming protocol developed by Apple. Unlike UDP based protoc...
Collapse
 
lblanks240 profile image
lblanks240

git clone git://github.com/arut/nginx-rtmp-module.git i attempted to down load this to my server this was the error is there another way to get this plugin?

thanks
lenard

[root@server ~]# git clone git://github.com/arut/nginx-rtmp-module.git
Cloning into 'nginx-rtmp-module'...
fatal: unable to connect to github.com:
github.com[0: 192.30.253.113]: errno=Connection refused

Collapse
 
lblanks240 profile image
lblanks240

i finally downloaded the module but now i get i have put this plugin in several places i am not sure what to do

Lenard

configuring additional modules
adding module in ../nginx-rtmp-module
./configure: error: no ../nginx-rtmp-module/config was found
[root@server nginx-1.17.0]# ls
auto conf html man README
CHANGES configure LICENSE nginx-rtmp-module.git src
CHANGES.ru contrib Makefile objs

Collapse
 
samuyi profile image
Samuyi

check the path specified for the cloned module and make sure the module was cloned without any errors. The config file that caused the error is located on the project root directory on github. So i suggest you make sure the path specified is the correct path to the module.

Thread Thread
 
lblanks240 profile image
lblanks240

what will be the best way to get this file without errors?

Thread Thread
 
lblanks240 profile image
lblanks240

i had to use wget to get the file

Thread Thread
 
lblanks240 profile image
lblanks240

i was wondering if you could please let me know if i got the conf file correct

thanks
lenard

* @version 1.8.10

* @package Engintron for cPanel/WHM

* @author Fotis Evangelou

* @url engintron.com

* @copyright Copyright (c) 2010 - 2018 Nuevvo Webware P.C. All rights reserved.

* @license GNU/GPL license: gnu.org/copyleft/gpl.html

*/

user nginx;
pid /var/run/nginx.pid;

worker_processes auto;
worker_rlimit_nofile 65535;
server_tokens off;

events {
multi_accept on;
use epoll;
worker_connections 65535;
}

We need to setup an rmtp server to stream video from client devices

rtmp {
server {
listen 1935;
chunk_size 4096;
ping 30s;
notify_method get;
allow play all;
# rmtp handler our clients connect to for live streaming, it runs on port 1935. It converts the stream to HLS and stores it on our server
application app {
live on;
hls on;

hls_path /var/www/hls/live;
hls_nested on; # create a new folder for each stream
record_notify on;
record_path /var/www/videos;
record all;
record_unique on;
}

application vod {
   play /var/www/videos;
}

}
}

http {
## Basic Settings ##
client_body_buffer_size 128k;
client_body_timeout 30s; # Use 5s for high-traffic sites
client_header_timeout 30s; # Use 5s for high-traffic sites
client_max_body_size 1024m;
keepalive_timeout 20s;
port_in_redirect off;
sendfile on;
server_names_hash_bucket_size 512;
server_name_in_redirect off;
server_tokens off;
tcp_nodelay on;
tcp_nopush on;
types_hash_max_size 2048;
include mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
sendfile on;
tcp_nopush on;
keepalive_timeout 65;
gzip on;
server {
listen 80;
server_name _;
location / {
root html;
index index.html index.htm;
}
# the http end point our web based users connect to see the live stream
location /live {
types {
application/vnd.apple.mpegurl m3u8;
}
alias /var/www/hls/live;
add_header Cache-Control no-cache;
}
}include mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
sendfile on;
tcp_nopush on;
keepalive_timeout 65;
gzip on;
server {
listen 80;
server_name _;
location / {
root html;
index index.html index.htm;
}
# the http end point our web based users connect to see the live stream
location /live {
types {
application/vnd.apple.mpegurl m3u8;
}
alias /var/www/hls/live;
add_header Cache-Control no-cache;
}
}

Collapse
 
arihantdaga profile image
arihant daga • Edited

This is very nice. Thank you for this article. I have a doubt. I wanted to make a webiste similar to netflix(On a smaller level, i understand), where i have few video files(Movies) and i want to stream those to the web browser.

I understood that i can convert all my files using ffmpeg. using this command

ffmpeg -i /path/to/video  -c:v h264 -c:a aac  -strict -2 -f flv rtmp://server_ip:1935/app/unique_stream_name     #the name of the stream has to be unique  

But Shall i do this will all my files only once and generate chunks. Or shall i issue this command every time a new user request a video. I have seen that these files under the directory /var/www/hls/live are lost on restarting nginx.

Collapse
 
samuyi profile image
Samuyi

As far as i know it has to be done for every request.

Collapse
 
littlerichard3755 profile image
littlerichard3755

Great article, I've been able to setup my server for streaming and able to livestream to the server and push to other platforms. I can also use VLC to view the live stream by xxx.xxx.xxx.xxx/live/123456/index...., however I am not able to view the livestream with an embedded player on a website. Is it due to crossdomain or do I need an SSL certificate, or am I leaving something out. your assistance would be greatly appreciated.

Collapse
 
terrancio profile image
terrancio

"ffmpeg -i /path/to/video -c:v h264 -c:a aac -strict -2 -f flv rtmp://server_ip:1935/app/unique_stream_name #the name of the stream has to be unique "

When it says /Path/To/Video what exactly should I put there? because I chose a directory thinking it's where I was gonna save video files, but after I pressed Enter it appeared in Red "It is a directory" so... may you help me, please?

Collapse
 
manas86 profile image
manas86 • Edited

Cool article. I'm just stuck on point 3. can you please explain a bit in details like server-ip from which server. Just missing a little piece of information on streaming part like you did for nginx

Collapse
 
samuyi profile image
Samuyi

The ip or hostname of the remote machine Nginx is running on

Collapse
 
scx1899 profile image
gti.scx1899@gmail.com • Edited

hi
please upload shell script fullconfig.sh this page install&config all level and set this page
Centos & ubanta

thanks