Welcome to World of IPTV

Join us now to get access to all our features. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, and so, so much more. It's also quick and totally free, so what are you waiting for?

Forum Rules

Our Rules: Read to avoid getting banned!

Advertising

Introduce Yourself to the World with Us!

Resource Database

Find the newest resources around IPTV!

Account upgrade

Upgrade your account to unlock more benefits!

Tutorial How To Install Nginx RTMP Server + HLS on Ubuntu 16.04 | EASY!

redhat

Administrator
Staff member
Administrator
Joined
Jun 19, 2019
Messages
3,299
Reaction score
15,912
Points
134
Location
root[@]woi
nginx-ffmpeg.png

How To Install Nginx RTMP Server + HLS on Ubuntu 16.04 | EASY!


Install the tools required to compile Nginx and Nginx-RTMP from source.
Bash:
sudo apt-get install build-essential libpcre3 libpcre3-dev libssl-dev


Download the Nginx and Nginx-RTMP source.
Bash:
wget http://nginx.org/download/nginx-1.14.0.tar.gz
wget https://github.com/arut/nginx-rtmp-module/archive/master.zip


Install the Unzip package.
Bash:
sudo apt-get install unzip


Extract the Nginx and Nginx-RTMP source.
Bash:
tar -zxvf nginx-1.14.0.tar.gz
unzip master.zip


Switch to the Nginx directory.
Bash:
cd nginx-1.14.0


Add modules that Nginx will be compiled with. Nginx-RTMP is included.
Apache config:
./configure --with-http_ssl_module --add-module=../nginx-rtmp-module-master


Compile and install Nginx with Nginx-RTMP.
Apache config:
make
sudo make install


Now Install the Nginx init scripts.
Bash:
sudo wget https://raw.github.com/JasonGiedymin/nginx-init-ubuntu/master/nginx -O /etc/init.d/nginx
sudo chmod +x /etc/init.d/nginx
sudo update-rc.d nginx defaults


Update the package lists.
Bash:
sudo apt-get update


Install FFmpeg.
Bash:
sudo apt-get install ffmpeg


Create the folder structures necessary to hold the live and mobile HLS manifests and video fragments:
Bash:
sudo mkdir /HLS
sudo mkdir /HLS/live
sudo mkdir /HLS/mobile
sudo mkdir /video_recordings
sudo chmod -R 777 /video_recordings


It’s probably a good idea to have your firewall turned on if you haven’t done so already. If so, you must allow traffic into the ports used by Nginx and HLS. If you’d like to run without the firewall for now, ignore the ufw section below.
Bash:
sudo ufw limit ssh
sudo ufw allow 80
sudo ufw allow 1935
sudo ufw enable


Now open the nginx configuration file
Bash:
sudo nano /usr/local/nginx/conf/nginx.conf


Remove the code and open this file and add this code to it
Bash:
#user nobody;
worker_processes  1;

error_log  logs/rtmp_error.log debug;
pid        logs/nginx.pid;

events {
    worker_connections  1024;
}

http {
    server {
        listen       80;
        server_name  localhost;

        location /hls {
            # Serve HLS fragments

            # 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/vnd.apple.mpegurl m3u8;
                video/mp2t ts;
            }
            root /tmp;
            add_header Cache-Control no-cache;
        }
    }
}

rtmp {
        server {
                listen 1935;
                chunk_size 8192;

                application hls {
                        live on;
                        meta copy;
                        hls on;
                        hls_path /tmp/hls;
        }
    }
}
Ctrl + X to save the file to disk and exit.

Before you do anything else, it’s important to take care of what is called “cross-domain” restrictions, which would otherwise shut down your ability to stream to a webpage/website. Create a crossdomain.xml file in your nginx/html folder and put instructions in it to allow data to flow between domains:
Bash:
sudo nano /usr/local/nginx/html/crossdomain.xml

First copy (from this page) and then paste (right-click) into the nano editor field the following XML data:
Bash:
<?xml version="1.0"?>
<!DOCTYPE cross-domain-policy SYSTEM "http://www.adobe.com/xml/dtds/cross-domain-policy.dtd">
<cross-domain-policy>
<allow-access-from domain="*"/>
</cross-domain-policy>
Press Ctrl + O to write out, then Ctrl + X to save the file to disk and exit.
And your done!

little info about your servers
FMS URL: rtmp://your-ip/hls/

Stream Key: ANY thing you like, I usually set it to stream.

again if you set your stream key to movie then it would look something like this
 
Last edited:
This is great!
I finally got it right. Perfect instruction on how to install NGINX.
Just like the title said ... EASY to install. I tried to install it on my Server many times a few months back .could not get it done.
Flussonnic I'm half way there my friend, another good software to do restreams I'll be gone with my $80 a month which I can hardly afford.(lol)
Thank you WORLDOFIPTV ...
 
Channels MatchTime Unblock CDN Offshore Server Contact
100 cnx / 90€ 5Gbps / 180€ 48CPU-256GRAM 10Gbps 569€ Skype live:giefsl
500 cnx / 350€ 10Gbps / 350€ 48CPU-128GRAM 5Gbps / 349€ TG @changcdn
1000 cnx / 500€ 20Gbps / 700€ 40CPU-128GRAM 20Gbps / €980 http://coronaserver.com
Channels MatchTime Unblock CDN Offshore Server Contact
100 cnx / 90€ 5Gbps / 180€ 48CPU-256GRAM 10Gbps 569€ Skype live:giefsl
500 cnx / 350€ 10Gbps / 350€ 48CPU-128GRAM 5Gbps / 349€ TG @changcdn
1000 cnx / 500€ 20Gbps / 700€ 40CPU-128GRAM 20Gbps / €980 http://coronaserver.com
Channels MatchTime Unblock CDN Offshore Server Contact
100 cnx / 90€ 5Gbps / 180€ 48CPU-256GRAM 10Gbps 569€ Skype live:giefsl
500 cnx / 350€ 10Gbps / 350€ 48CPU-128GRAM 5Gbps / 349€ TG @changcdn
1000 cnx / 500€ 20Gbps / 700€ 40CPU-128GRAM 20Gbps / €980 http://coronaserver.com
thanks, I tested good working but hls stream 1 minutes behind from orginal stream. how to set hls stream 10-15 seconds behind orginal stream, How to build low latency time nginx for hls stream
 
Last edited:
Hi, good job, do you have any tutorials that can explain how to add streams? Thanks.
 
Channels MatchTime Unblock CDN Offshore Server Contact
100 cnx / 90€ 5Gbps / 180€ 48CPU-256GRAM 10Gbps 569€ Skype live:giefsl
500 cnx / 350€ 10Gbps / 350€ 48CPU-128GRAM 5Gbps / 349€ TG @changcdn
1000 cnx / 500€ 20Gbps / 700€ 40CPU-128GRAM 20Gbps / €980 http://coronaserver.com
nginx-ffmpeg.png

How To Install Nginx RTMP Server + HLS on Ubuntu 16.04 | EASY!


Install the tools required to compile Nginx and Nginx-RTMP from source.
Bash:
sudo apt-get install build-essential libpcre3 libpcre3-dev libssl-dev


Download the Nginx and Nginx-RTMP source.
Bash:
wget http://nginx.org/download/nginx-1.14.0.tar.gz
wget https://github.com/arut/nginx-rtmp-module/archive/master.zip


Install the Unzip package.
Bash:
sudo apt-get install unzip


Extract the Nginx and Nginx-RTMP source.
Bash:
tar -zxvf nginx-1.14.0.tar.gz
unzip master.zip


Switch to the Nginx directory.
Bash:
cd nginx-1.14.0


Add modules that Nginx will be compiled with. Nginx-RTMP is included.
Apache config:
./configure --with-http_ssl_module --add-module=../nginx-rtmp-module-master


Compile and install Nginx with Nginx-RTMP.
Apache config:
make
sudo make install


Now Install the Nginx init scripts.
Bash:
sudo wget https://raw.github.com/JasonGiedymin/nginx-init-ubuntu/master/nginx -O /etc/init.d/nginx
sudo chmod +x /etc/init.d/nginx
sudo update-rc.d nginx defaults


Update the package lists.
Bash:
sudo apt-get update


Install FFmpeg.
Bash:
sudo apt-get install ffmpeg


Create the folder structures necessary to hold the live and mobile HLS manifests and video fragments:
Bash:
sudo mkdir /HLS
sudo mkdir /HLS/live
sudo mkdir /HLS/mobile
sudo mkdir /video_recordings
sudo chmod -R 777 /video_recordings


It’s probably a good idea to have your firewall turned on if you haven’t done so already. If so, you must allow traffic into the ports used by Nginx and HLS. If you’d like to run without the firewall for now, ignore the ufw section below.
Bash:
sudo ufw limit ssh
sudo ufw allow 80
sudo ufw allow 1935
sudo ufw enable


Now open the nginx configuration file
Bash:
sudo nano /usr/local/nginx/conf/nginx.conf


Remove the code and open this file and add this code to it
Bash:
#user nobody;
worker_processes  1;

error_log  logs/rtmp_error.log debug;
pid        logs/nginx.pid;

events {
    worker_connections  1024;
}

http {
    server {
        listen       80;
        server_name  localhost;

        location /hls {
            # Serve HLS fragments

            # 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/vnd.apple.mpegurl m3u8;
                video/mp2t ts;
            }
            root /tmp;
            add_header Cache-Control no-cache;
        }
    }
}

rtmp {
        server {
                listen 1935;
                chunk_size 8192;

                application hls {
                        live on;
                        meta copy;
                        hls on;
                        hls_path /tmp/hls;
        }
    }
}
Ctrl + X to save the file to disk and exit.

Before you do anything else, it’s important to take care of what is called “cross-domain” restrictions, which would otherwise shut down your ability to stream to a webpage/website. Create a crossdomain.xml file in your nginx/html folder and put instructions in it to allow data to flow between domains:
Bash:
sudo nano /usr/local/nginx/html/crossdomain.xml

First copy (from this page) and then paste (right-click) into the nano editor field the following XML data:
Bash:
<?xml version="1.0"?>
<!DOCTYPE cross-domain-policy SYSTEM "http://www.adobe.com/xml/dtds/cross-domain-policy.dtd">
<cross-domain-policy>
<allow-access-from domain="*"/>
</cross-domain-policy>
Press Ctrl + O to write out, then Ctrl + X to save the file to disk and exit.
And your done!

little info about your servers
FMS URL: rtmp://your-ip/hls/

Stream Key: ANY thing you like, I usually set it to stream.

again if you set your stream key to movie then it would look something like this
verry verry thanks bro
 
nice guide. I'll try these steps. Will it work on Ubuntu 18.04 ?
 
Channels MatchTime Unblock CDN Offshore Server Contact
100 cnx / 90€ 5Gbps / 180€ 48CPU-256GRAM 10Gbps 569€ Skype live:giefsl
500 cnx / 350€ 10Gbps / 350€ 48CPU-128GRAM 5Gbps / 349€ TG @changcdn
1000 cnx / 500€ 20Gbps / 700€ 40CPU-128GRAM 20Gbps / €980 http://coronaserver.com
Tell me how can I add a regular stream here, which goes through http// ???
 
when i have added this ffmpeg order in ubuntu, the broadcast start succefully.

input : iptv (.ts - m3u8)
output : rtmp:// (youtube-...)

root@ssdz:~# exec ffmpeg -i http://**iptv**.ts -threads 1 -c:v libx264 -profile:v baseline -b:v 1200K$ 1200K -s 720x576 -f flv -c:a aac -ac 1 -strict -2 -b:a 128k rtmp://output;



and when i add this order ffmpeg in nginx and i restart nginx .
the broadcast don't start .

rtmp {
server {
listen 1935;
chunk_size 4096;

application live {
live on;
record off;
allow publish 127.0.0.1;
allow publish 138.201.145.138;
deny publish all;
exec ffmpeg -i http://**iptv**.ts -threads 1 -c:v libx264 -profile:v baseline -b:v 1200K$ 1200K -s 720x576 -f flv -c:a aac -ac 1 -strict -2 -b:a 128k rtmp://output;
}
application live720p {
live on;
record off;
allow publish 127.0.0.1;
allow publish 138.201.145.138;
}
}
}
 
Thank you so much for the script.
 
Channels MatchTime Unblock CDN Offshore Server Contact
100 cnx / 90€ 5Gbps / 180€ 48CPU-256GRAM 10Gbps 569€ Skype live:giefsl
500 cnx / 350€ 10Gbps / 350€ 48CPU-128GRAM 5Gbps / 349€ TG @changcdn
1000 cnx / 500€ 20Gbps / 700€ 40CPU-128GRAM 20Gbps / €980 http://coronaserver.com
Clear instructions ! Well done
 
shape1
shape2
shape3
shape4
shape5
shape6
Back
Top