HLS Streaming Server with NGINX

  • 3,679 views. Added .

Want to make your own streaming server so you can deliver live HTTP video to your website? Grab a VPS and strap in, because it's easier than you might think!

Affiliate links for DigitalOcean and Linode:
https://digitalocean.nots.co
https://linode.nots.co

Guide used as a reference for this video (not comprehensive): https://docs.peer5.com/guides/setting-up-hls-live-streaming-server-using-nginx/

Currently-maintained NGINX RTMP module fork: https://github.com/sergey-dryabzhinsky/nginx-rtmp-module

Comments (log in to post)

Hello  guys .. hope  y'all doing great … could somebody please help on how to  restream   an  hls  stream from another source using  nginx and  how to set stream quality  depending on  the internet  quality  like how  youtube    is ….. God bless that person who is will help me  solve that challenge
Hi, can you tell me what's kind of problem?
properly installed nginx and msde config file.
root@vps-ec07fa56:/home/ubuntu# /usr/local/nginx/sbin/nginx -g 'daemon off;'
nginx: [emerg] bind() to 0.0.0.0:443 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:443 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:443 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:443 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:443 failed (98: Address already in use)
nginx: [emerg] still could not bind()
I had the same problem with the 443 failure to bind. I found that SUDO fuser -k 443/tcp worked That said I was never able to get NGINX to send my stream to the HLS player and I was never able to get it to play on my website. I really injoyed the VID and found it helpful, but I think there may have been some updates along the way and maybe a couple of steps might have changed...? I am still trying to figure this one out... Admittedly I am a newbie at linux and I am sure I am missing something here.
Another application is already listening on port 443 on the server. You can only have one application listening on port 443 at a time. You need to stop the other applications listening on that port (or set up proxying from one application to another if you actually need more than one.)
How can I renewal Let’s Encrypt certificates?

eltayeb47 said

Thank you very much for your effort and great explanation, but in fact, I have two questions     
Hello, welcome. I have a live match streaming website and I have ubuntu 18.4 CPU 8 ram 32320 SSD, but when it is used on the site the number of simultaneous internet callers is no more than 1000.
But I want more traffic to my site
The broadcast is interrupted when I reach 1000 viewers online at one time, but have more than that number at one time and exceed 10,000 viewers at one time?
First of all, do I have to do load balance and can I do it this way? Is there an explanation to describe this method and how it works?
Second, what is installed on the backend servers, and what are its steps?

Third, how to work more than one channel at one time
Thank you very much for your effort and great explanation, but in fact, I have two questions     
Hello, welcome. I have a live match streaming website and I have ubuntu 18.4 CPU 8 ram 32320 SSD, but when it is used on the site the number of simultaneous internet callers is no more than 1000.
But I want more traffic to my site
The broadcast is interrupted when I reach 1000 viewers online at one time, but have more than that number at one time and exceed 10,000 viewers at one time?
First of all, do I have to do load balance and can I do it this way? Is there an explanation to describe this method and how it works?
Second, what is installed on the backend servers, and what are its steps?
Hi! Thanks for the great tutorial!

I am having some issues with streaming though.

I am running Nginx on a seperate Ubuntu server and OBS on my computer. However, after entering the Server name in OBS (http://<server>/show)
OBS displays an error saying it failed to connect to the server. My Nginx is able to run and I am able to ssh to the server. I have also tried to telnet the Nginx server's 1935 port, but there it shows a failed connection. However, I have already opened all the necessary ports on my server.

Can the issue be caused from any closed ports? (eg. 1935)

Any help would be fantastic!
Thank you!
Hi Jacob,

First of all thank you so much for producing these videos. So much heartache avoided by clean and robust tutorials. A very welcome godsend.

I am struggling to make hls stream over https.

I have followed your previous video to the letter and have live streaming and restreaming over http.

I am also using Digital Ocean and LetsEncrypt. I have the certificates installed and from this video above I can see these in the appropriate folder. I have added, as per your instructions, the locations within nginx.conf.

I generally use "sudo systemctl restart nginx" with no errors; but have checked using your syntax and can see .m3u8 data being created.

I am a a complete loss and been at this https challenge for four days solid.

I'd be very grateful if you could shed some light or pointers to get this moving.


**********
UPDATE
**********
Watching your video again I've carefully went over the steps and the debugging protocols you use.

My server video is showing a 404 error but attributed to nginx 1.14, which I know is the Digital Ocean version, which I've never installed but somehow its in there. Note that my http stream works.

I ran your commands, found around 25 minutes in, to purge python-certbox-nginx:

root@200630-hls-restream-nohttps-s-1vcpu-2gb-lon1-01:~# sudo apt purge python-certbox-nginx
Reading package lists… Done
Building dependency tree
Reading state information… Done
E: Unable to locate package python-certbox-nginx
root@200630-hls-restream-nohttps-s-1vcpu-2gb-lon1-01:~# sudo apt remove nginx*
Reading package lists… Done
Building dependency tree
Reading state information… Done
E: Unable to locate package nginx-1.19.0
E: Couldn't find any package by glob 'nginx-1.19.0'
E: Couldn't find any package by regex 'nginx-1.19.0'
E: Unable to locate package nginx-rtmp-module

I can restart nginx and can send a stream to it, but again I have this nginx 1.14 404 error.

Your video goes too quick for me to see how to remove nginx1.14 and I'm now scared to touch anything :-D

I've also posted on this video's forum thread.

Hi Jacob,

Excellent tutorial!  Quick question, still having an issue with sending the HLS data into my web site, the player keeps going into a loading loop after hitting 'play'.  RTMP seems to be working, able to open the stream in VLC (rtmp://mydomain:8080/show/live.m3u8).   Do I need to add anything under the http or HLS/application sections of the nginx.conf or could I be missing something else?

Ubuntu: 18.04
Nginx: 1.14 (hosting both www and rtmp)
VPS: AWS

Thanks in advance for your help and stay safe.

P.
I would assume you need to be able to play back the m3u8 feed using http:// or https:// (whichever your website is using) and without specifying port 8080:. You need to add the things under the http section that I added in this video. A web browser needs to be able to visit the .m3u8 link and download the m3u8 manifest. If it can, then a video player should be able to play the video back as well.
Thanks a lot Jacob, it is working now.
Hello
Nice tutorial.
Do you have some similar stream solution, for webrtc?
Good afternoon Jacob, I hope you are well.

I tell him I managed to implement my HLS server, and now that I buy a decoder to see the transmission that is sent to the server through RTMP, the decoder does not connect to the server since it only recognizes formatted addresses:

example:
transmission link: rtmp: //rtmp.mine.com.cn/live/0315
reproductor link: rtmp: //pay.mine.com.cn/live/0315

Do you think there was a solution?
Hi there!

marpensa said

now that I buy a decoder to see the transmission
Why do you need to buy a decoder? ffmpeg is the encoder, NGINX is the transcoder, the web browser is the decoder. All major web browsers are currently able to play HLS, and even the ones that can't natively can do so through a video player like VideoJS.

marpensa said

example:
transmission link: rtmp: //rtmp.mine.com.cn/live/0315
reproductor link: rtmp: //pay.mine.com.cn/live/0315
"Reproductor" is not an English word, but I get the idea. However, your playback URL is not going to start with rtmp:, it's going to start with http: or https: (hence, why it's called HTTP Live Streaming) and it's going to end with .m3u8. You can play back the RTMP URL using a player that can decode RTMP, but the point of this video and the setup I demonstrated was to have NGINX decode it into HLS so clients can watch directly. Does that make sense? If not, then I'd need some more clarification on what you're trying to accomplish.