Categories
IT Servers Streaming

My HLS Server

The second server took a lot of work to get correct. It was much harder but the work payed off and it’s functional. I’m still trying to upgrade it to get better statistics about how many people are using the app to watch live but I have some going now.

HLS and Re-stream server configuration using 2 separate servers
We use this server in the above configuration. In ours, the RTMP streaming server is now a node.js node-media-server according to https://timdrones.com/2020/05/12/another-type-of-re-stream-server/

To make this part function, the server takes in an RTMP stream and converts it using ffmpeg to make it an HLS .m3u8 file. That file is then the target of a link in the apps control panel that tells it to get the stream on a users phone and display our live service. Each user of the app who watches within the app is connected to the HLS streaming server and so we have to scale this one up to use it well.

I have a snapshot of the server that is in AWS Lightsale and when we need it I can spin it up to be what would cost $40 a month. But we only need it for a couple hours. Then we delete it. So it costs about 12 cents to run each week for our live service on Wednesday. I just transfer over the dns records and IP address information and allow the proper ports on the firewall and in 5 minutes it’s ready to go.

I also found data about statistics by searching for “stub_status Nginx” on Google. That led me to information such as: https://www.google.com/amp/s/easyengine.io/tutorials/nginx/status-page/%3Famp

The configuration is similar to the RTMP re-streamer in that they both use Ubuntu and NGINX and this one needs ffmpeg to do its conversions of the RTMP feed into the HLS feed for the app.

I used a tutorial I found online to begin this one as well. It’s found below.

After going around and around trying to recompile Nginx with the stub_status module, I found the tutorial that told me how to check if it was already installed. It turns out it was. So that was good however I wasted a lot of time trying to install it and a c compiler when I didn’t need to.

If you’d like to see my NGINX.conf file for the HLS streaming server an example of it is here. If you’d like it to also stream to other services you can use it, but you have to modify it a little bit like the RTMP server that I posted about previously. Facebook only accepts “secure” rtmp so you have to pass it’s feed through “stunnel”. Here’s my nginx.conf file. I also put in the “Streamingserver.xyz.conf” file that you will need in the sites-available folder on the server. This file should be named after your proper registered domainname and .com or .org or .xyz or whatever your domain name is. The default file below is “default” as seen in the sites-available folder on the server as well. These are all in “/etc/nginx/nginx.conf” or the others are in “/etc/nginx/sights-available/”. If you follow along in the examples that I gave above from the links to outside sites, you can see that you’ll make a link between the sites-available folder and two files in the sites-enabled folder with the same names of “default” and “yourserver.something.conf”. Also while I was creating this, I had to stop the apache server because it was interfering. I had to issue the command “sudo systemctl stop apache2”. It was causing errors.

If you’re interested in the app we use it’s The Church App from Subsplash.

Categories
IT Servers Streaming

Statistics and Webpage for HLS server

I need a few statistics for the HLS server because as you stream the .m3u8 file, it’s a bit hard to tell how many people are using the app to watch it. I’ve inserted a couple statistics pages on this server to help get a better pictures of who’s using it.

The first way is to use the RTMP streaming statistics as seen in the /etc/nginx/sites-available/default file at the location at the bottom.

## XML stylesheet to view RTMP stats. Copy stat.xsl wherever you want and put the full directory path here
location /stat.xsl {
	root /var/www/html/;
	}
## This provides RTMP statistics in XML at 
location /stat {
	rtmp_stat all;
	rtmp_stat_stylesheet stat.xsl;
	}

This outputs a nice little page that looks like below:

The next bit of Stats that I added was the below. This is from the stub_status output. It’s very simple and only somewhat useful, but it’s a start on seeing how many people are on my .m3u8 feed. The active connections is the useful part however because of the internal connections and my own viewing of this page, out of the 11 seen connections I think only about 3 or so are actually users on our app in the below case.

I put in a little index.html file to replace the original that tells you Nginx on a standard install of Nginx. I made my page just give a few links to the various status reports on the server. It makes it a little bit easier to use and will help when I train others to use these servers later. The status page looks like the below:

This is made with an index.html file with the links to the low resolution, high resolution HLS feeds as well as the two status pages.

  • Connection link: https://your_domain_name_here.xyz/nginx_status
  • RTMP feed status: https://your_domain_name_here.xyz/stat.html
  • Low Res link: https://your_domain_name_here.xyz/low.html
  • High Res link: https://your_domain_name_here.xyz/live.html

I’m still trying to find more ways to get better statistics out of the HLS feed use, however I haven’t gotten there yet. I’ll probably keep this updated to tell others when I find more ways to do it.

Categories
IT Servers Streaming

Streaming to Facebook and YouTube with only a Phone Camera

If you are only streaming to Facebook alone because you don’t have an expensive camera or computer hardware to send out your feed there’s a solution for you.

Many churches have been caught off guard by our current situation and have taken to streaming their services. Many churches have also been simply streaming to Facebook Live because it’s easy to just set up a phone on a tripod and start streaming. If you do this, it’s hard to also stream to YouTube, however I have a solution for you.

This solution will look much like my diagrams seen on the other pages of this blog. You can use a re-streaming server like the one seen here : https://timdrones.com/2020/05/01/simple-re-stream-server-instructions/. This will let you send out your stream to any services you like for Live broadcast.

Instead of just using your Facebook app on your phone to send only to Facebook, you can use an RTMP streamer from either an iPhone or an Android phone. That way you can send that feed to your re-streaming server as seen in the above paragraph and use that to send your feed to Facebook and YouTube both at the same time. You will only need a computer to tell each of them to “go live”.

I have personally tested this method with an iPhone and an Android phone. On the iPhone I have the app called “Broadcaster” and another app “Streamlabs: Stream Live”. On the Android phone I have the app called “Streamlabs”. I use each of these apps to test my streaming servers while I create them.

On “Broadcaster” for the iPhone you can fill in your server information in the middle where it says “Stream host”, you just fill in your server as such: “rtpm://<Your IP of your Server>/live/”, then under that in the part where it says “Stream Key” you put in your made up stream key like you created from the tutorial, in the part where it talks about OBS or hardware encoder. It was “test” in our example on the other page. It doesn’t really matter what your stream key is for your input to the server. Just use something easy and consistent so you can easily refer back to it if you need to.

On Streamlabs for the iPhone you can click on the “Other Platforms link at the very bottom below the options for streaming websites. that is where you’ll put in the custom RTMP setup just like above. You’ll put in the server as such: “rtpm://<Your IP of your Server>/live/”, then under that in the part where it says “Stream Key” you put in your made up stream key like you created from the tutorial.

For Streamlabs for the Android phone you use the little menu lines on the top left, to then choose Settings. In Settings you choose “Streaming platform”, at the very bottom of the list you choose “Custom RTMP server” and you put in the server as such: “rtpm://<Your IP of your Server>/live/”, then under that in the part where it says “Stream Key” you put in your made up stream key like you created from the tutorial.

Categories
4k IT Servers Streaming

Another Nginx Re-Streamer With HLS Output

Recently I had a request to see if I would be able to provide some sort of a tutorial on how to make a re-streaming server for Facebook and YouTube as well as having an HLS output as well, preferably with various resolutions.

My server is based on the rtmp-module in nginx. We should install this on an Ubuntu server from Lightsail. I usually make a very small one for $3.50 per month, but then if I want to stream with HLS I need to use a snapshot and create a new instance that is much larger. Otherwise it won’t be able to handle all the transformations of the data to make the HLS files and it will fail.

This server in the stock configuration as shown will re-stream to any other RTMP locations that you need and also send out HLS to places in various resolutions. If you send it a 1080p 30fps input, it will send out a 1080, 720, and 360 HLS output as well. If you make some adjustments that I show in an optional section, then you can make it take in 4k and re-stream that to any RTMP places you wish, plus output on HLS 4k, 1080, 720, and 360.

Install nginx and update ubuntu

sudo apt update
sudo apt upgrade
sudo apt install -y nginx
sudo apt install -y libnginx-mod-rtmp

Now we have to install a bunch of needed packages to allow for the media streaming to properly occur.

sudo apt install -y software-properties-common
sudo dpkg --add-architecture i386
sudo apt update

The entire below code should be copied and pasted in its entirety at once.

sudo apt install wget nano python-certbot-nginx ufw unzip software-properties-common dpkg-dev git make gcc automake build-essential joe ntp ntpdate zlib1g-dev libpcre3 libpcre3-dev libssl-dev libxslt1-dev libxml2-dev libgd-dev libgeoip-dev libgoogle-perftools-dev libperl-dev pkg-config autotools-dev gpac ffmpeg sysstat nasm yasm mediainfo mencoder lame libvorbisenc2 libvorbisfile3 libx264-dev libvo-aacenc-dev libmp3lame-dev libopus-dev libfdk-aac-dev libavcodec-dev libavformat-dev libavutil-dev g++ libc6:i386 freeglut3-dev libx11-dev libxmu-dev libxi-dev libglu1-mesa libglu1-mesa-dev
sudo apt install mariadb-server mariadb-client phpmyadmin php php-cgi php-common php-pear php-mbstring php-fpm

These are to allow for the rtmp module to be installed and the statistics to be made.

cd /usr/src

sudo git clone https://github.com/arut/nginx-rtmp-module

sudo cp /usr/src/nginx-rtmp-module/stat.xsl /var/www/html/stat.xsl

This is the crossdomain file

sudo nano /var/www/html/crossdomain.xml

Paste the below into that file.

<?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>

This is the info.php file.

sudo nano /var/www/html/info.php

Paste the below into that file.

<?php
phpinfo();
?>

This is to create the locations of the hls streams.

sudo mkdir /var/livestream
sudo mkdir /var/livestream/hls
sudo mkdir /var/livestream/med
sudo mkdir /var/livestream/low

This is to give the proper permissions the livestream location can be used.

sudo chown -R www-data: /var/livestream

Now we have to create the nginx.conf file. This is where the majority of the server gets its programing.

sudo nano /etc/nginx/nginx.conf

The below file should be used as the nginx.conf file. I took off the .conf extension and made it a .txt so the site would allow me to post it.

In all the files that I have here, if you use them, please be sure to change the IP to your IP address. You will have to change them by using “sudo nano” and the file name such as nginx.conf. If you click on the link below that says “nginx”, it will open up a new browser window and you can copy and paste this into your nginx.conf file.


Skip this section if you don’t need 4K.

Below is the nginx.conf file that you should use if you want the streamer to make 4 types of HLS files. It can take 4k and create 4k, 1080, 720 and 360 outputs. But it needs a very large server to do it all. Also you’ll have to create the proper html files that allow you to show people the created outputs, or just use it to send to other services. I didn’t include the proper html files in this tutorial. You should name this “nginx.conf” if you use it.

Remember that you’ll also need to make directories where the “high” files will be stored.


sudo nginx -t
sudo systemctl restart nginx
sudo nano /etc/nginx/sites-available/default

The below default.txt is actually the file that is from /etc/nginx/sites-available/default. I added the .txt extension to it so it would allow me to post it properly. You should delete the .txt extension to make it work if you want to use it directly, or just copy and paste it into the default file when you are in the nano program.

sudo nginx -t
sudo systemctl restart nginx

So that we can create and use a website to manage and check on these streaming server functions we have to have a video player that will play our HLS files on a website. The first two lines below should be copied and pasted individually. The “sudo wget” sections should be done as sections. That will get the .zip file and the .js file that you will need for the video player.

sudo mkdir /var/www/html/videojs
cd /var/www/html/videojs

sudo wget https://github.com/videojs/video.js/releases/download/v7.7.6/video-js-7.7.6.zip

sudo wget https://github.com/videojs/http-streaming/releases/download/v1.13.1/videojs-http-streaming.js

The following lines should be done individually and they will all the video player to be unzipped as well as make the proper allowance for it to be used with the directories we created.

sudo unzip /var/www/html/videojs/video-js-7.7.6.zip
sudo chown -R www-data: /var/www/html
sudo ls -la /var/www/html/videojs

Now we have to make the page that will show the options for the server.

We have to make the index.html page as well as the pages for the videos, low.html, med.html, live.html.

Here are some copies of my files. You’ll have to modify them slightly and add in your IP address on each of them to make them operate. Just replace the IP in some of the lines with your IP.

Note that these are very poor HTML code. I just made them quickly so that I could get a working page for myself. They aren’t neat and they aren’t good. They just work. Maybe sometime in the future I might fix them a bit, but for now I have other things that are more pressing than making them nice and pretty.

sudo nano /var/www/html/index.html
sudo nano /var/www/html/live.html
sudo nano /var/www/html/med.html
sudo nano /var/www/html/low.html

The index file below is set up for making 3 outputs (Low, Med, Live). The Live file output is the same stream output resolution that the input comes into the server. The below is a rough index.html file. It should make a workable webpage where you can choose to see some of your stats or a feed from each of the 3 above resolutions.

<h2 style="text-align: center;"><strong>Streaming Status Pages</strong>&nbsp;</h2> <p style="text-align: 
center;">&nbsp;</p> <p style="text-align: center;"><a href="https://(YOUR IP.Address)/nginx_status" target="_blank" 
rel="noopener">Status of Connections</a></p> <p style="text-align: center;">&nbsp;</p> <p style="text-align: 
center;">&nbsp;</p> <p style="text-align: center;"><a href="https://(YOUR IP.Address)/stat.html" target="_blank" 
rel="noopener">Status of the Stream</a></p> <p>&nbsp;</p> <p style="text-align: center;">&nbsp;</p> <p 
style="text-align: center;">Feed for Computers? <a href="https://(YOUR IP.Address)/live.html" target="_blank" 
rel="noopener">Live Stream "Full 1080 Resolution"</a></p> <p style="text-align: center;">&nbsp;</p> <p 
style="text-align: center;">&nbsp;</p> <p style="text-align: center;">Feed for the App: <a 
href="https://(YOUR IP.Address)/low.html" target="_blank" rel="noopener">Live Stream "Low Resolution"</a></p> <p 
style="text-align: center;">&nbsp;</p> <p style="text-align: center;">&nbsp;</p>

<p style="text-align: center;">Feed for Computers?: <a href="https://(YOUR IP.Address)/med.html" target="_blank" 
rel="noopener">Live Stream "720 Resolution"</a></p> <p style="text-align: center;">&nbsp;</p> <p 
style="text-align: center;">&nbsp;</p> <p style="text-align: center;">&nbsp;</p> <p style="text-align: 
center;">&nbsp;</p> <p style="text-align: center;">&nbsp;</p>
<p>&nbsp;</p>

Now you should test it all by streaming to your RTMP location at rtmp://IP/live/stream. If it takes hold and your streamer attaches then you can click on the websites links to check the feed.

After we have that all running. We have to get stunnel so that facebook will work. We’ll go back to the command prompt from your server. Issue the following commands to get stunnel.

sudo apt-get install stunnel4 -y

Now we’ll have to change stunnel’s boot configuration, issue the following command:

sudo nano /etc/default/stunnel4

Change Enabled from 0 to 1. It should look like the following:

ENABLED=1

Next we have to edit the stunnel configuration file.

sudo nano /etc/stunnel/stunnel.conf

You’ll have to cut and paste this in its entirety. It should look like this:

pid = /var/run/stunnel4/stunnel.pid
output = /var/log/stunnel4/stunnel.log
setuid = stunnel4
setgid = stunnel4
# https://www.stunnel.org/faq.html
socket = r:TCP_NODELAY=1
socket = l:TCP_NODELAY=1
debug = 4
[fb-live]
client = yes
accept = 1936
connect = live-api-s.facebook.com:443
verifyChain = no

Then of course you’ll have to use ctrl-x to exit, and Y to save it as the original named file.

Next we have make it enabled after boot by doing the following:

sudo systemctl enable stunnel4.service

Now we have to restart stunnel because we changed the configuration files.

sudo systemctl restart stunnel4.service

Now since we changed the stunnel configuration and all we should restart NGINX for good measure.

sudo systemctl restart nginx
Categories
IT Servers Streaming

Simple Re-Stream Server Instructions

HLS and Re-stream server configuration using 2 separate servers

Note: If you use Wirecast for streaming, you might want to try my other re-streaming server instructions as our Mac version of Wirecast didn’t like this one much. It wasn’t perfectly reliable. Howevever our hardware streamer worked great with this one, and other people have great success with it with other streamers as well. The linked one works well with Wirecast. https://timstreams.com/another-type-of-re-streamer-using-node-js/

I have been asked a few times for some very simple to follow server creation instructions that people can follow to make a server that can take a single RTMP feed and send it along to multiple services. In this case I have personally used this to send a stream to Facebook and YouTube at the same time. It only requires going to the Facebook and YouTube pages and telling them to start the live post.

I just went through the following steps and created a new streaming server in about 20 minutes. It was very fast and I didn’t really think much about what I was doing. I just sort of blindly followed this. At the end I tested it with my Facebook page and it said it was receiving it and was ready for me to go live.

This process I describe uses Amazon Lightsail servers that are very cheap and easy to use. The server that’s needed is $3.50 per month. In the cases I’ve been asked about churches are trying to do this and I assume you would need this for something like Sunday and Wednesday night each week. This would use about 5GB of data each time, so about 10 to 20GB per week. Which means about 80GB per month for the input stream. If you send this to Facebook and YouTube you are also sending out 160GB per month out of the server. This is well within the 1TB per month that the Lightsail small server gives you included for your $3.50.

The first step in the process is to to to Amazon Lightsail. The website address is : https://aws.amazon.com/free/compute/lightsail/ They even have a one month free trial of their services for the smallest one. That’s the one we want so it’s great just to try for this. So even if you don’t know what you’re really doing, you aren’t even out anything to try.

This image has an empty alt attribute; its file name is Screen-Shot-2020-05-01-at-12.08.21-PM-1024x576.png
This image has an empty alt attribute; its file name is Screen-Shot-2020-05-01-at-12.10.44-PM-1024x576.png

Go to Get Started Now and begin. You’ll have to create an Amazon AWS account to start, but that’s easy. (I bet you’ll like it after the first month too) I can’t go back through this because I already have an account. I don’t think I can walk you through some of those details because of that.

However once you are through with that, you should get to a page that looks like this:

This image has an empty alt attribute; its file name is Screen-Shot-2020-05-01-at-11.13.09-AM-1024x576.png

From here you choose your instance location. I always choose Northern Virginia for two reasons. One is that I’m located 40 miles from these server farms. Two is that these are probably some of the fastest server farms in the world.

This image has an empty alt attribute; its file name is Screen-Shot-2020-05-01-at-11.13.16-AM-1024x576.png

Next you have to pick the OS for the server. Also you have to choose “OS Only” and I choose Linux with Ubuntu being the image I want. It runs the software amazingly and the instructions assume these choices. Now we have to name our “instance”. I like something like “re-streamer” or something of the sort.

Next you have to wait for it to be created, that takes about a minute or less. Once it’s up and running, we can log into it via the browser. That is very simple and you just click the hyperlinked name of your server. That brings you to a page with a huge button that says “Connect Using SSH”. That’s what we want.

Then it brings you to a command prompt. This is where we’ll issue all our commands to make the server do all our work.

The following directions mostly follow from the following page: https://sites.google.com/view/facebook-rtmp-to-rtmps/home

Now that we have a server created and the instance is running and we are in the command prompt.

The first step is to install Nginx and Stunnel. Stunnel is what’s needed to make Facebook work, it requires an RTMPS feed. If you don’t want Facebook to work, it’s even easier because you can leave a few steps out. We won’t go into that in this post because most people want to stream to Facebook and YouTube at least.

To install Nginx and Stunnel we do the following: (litterally) copy and paste these each individually into the command prompt and hit enter. Some of them will ask questions as you go, like do you want to continue, it will take some amount of disk space. You have to agree, but it is always small and we have 20 usable GB of disk space. We’re not concerned. You also will get a couple windows like in the pictures below, choose YES on them or choose the Top Choice. These windows with the images need to be selected with the arrow keys to highlight the choice and then use the enter key to choose it.

If while you’re using the command prompt you have to re-type the last thing you did before, you can just hit the up arrow key. It will retype the last command automatically. Also as a note in the command prompt the mouse can’t be used to move the cursor, you have to use the arrow keys.

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install nginx -y
sudo apt-get install libnginx-mod-rtmp -y
This image has an empty alt attribute; its file name is Screen-Shot-2020-05-01-at-11.19.47-AM-1024x576.png
This image has an empty alt attribute; its file name is Screen-Shot-2020-05-01-at-11.21.36-AM-1024x576.png

This is totally optional: What I like to do occasionally is take a “snapshot” of the instance. This makes a copy of it’s drive and allows us to recreate it immediately if we mess anything up. The snapshot is like our backup plan if we really destroy this thing. It will save time if you have go try again. The only downside is that we pay a few cents a month to store each snapshot. You can delete any of them at any time.

Next we’ll edit the configuration file that runs Nginx. This file is what does most of the work that we need. The configuration is how we tell it what we want to do. Cut and paste the below into the command prompt.

sudo nano /etc/nginx/nginx.conf

At the very bottom of the nginx.conf file, under the other stuff that’s already there, paste this in in it’s entirety:

rtmp {
        server {
                listen 1935;
                chunk_size 4096;
                application live {
                        live on;
                        record off;
                        push rtmp://127.0.0.1:1936/rtmp/<<Facebook persistent stream key >>;
push rtmp://a.rtmp.youtube.com/live2/<<YouTube persistent stream key >>;
                }
        }
}

You’ll have to insert your Facebook persistant key in place of the note in this code. The key should go between the / and the ; This push command sends our stream and Facebook Key to stunnel so it can be made secure for Facebook to accept it. Below this “push” command we can put another in so we can send to YouTube or anywhere else we want. You can see an example from my personal nginx.conf file below. For YouTube you’ll have to add a push command that sends it to “rtmp://a.rtmp.youtube.com/live2/”. You’ll have to put your KEY after the last / and then put a ; at the very end of that line.

This image has an empty alt attribute; its file name is Screen-Shot-2020-05-01-at-1.13.27-PM.png
Insert your new part below the commented out parts that are already there.

After you’ve modified the nginx.conf file you have to save it and close it, so you press cntrl-x, then it will ask if you want to do that to the current named file and you hit the Y key, and then press enter for it to save the file.

If you need to keep other streamkeys and push commands in there when they aren’t needed, you can comment them out by using the # symbol at the start of the line. That makes the computer skip over that line and just go to the next one.

Now we have to restart Nginx because we’ve modified the configuration file. Paste in the following command into the command line.

sudo systemctl restart nginx

When you attempt to restart nginx, if it doesn’t work, you have errors in that nginx.conf file. You have to be sure it looks just like the examples or it won’t run properly and will fail. Be sure you have ;’s after the lines of the push commands.

If at any point you have to re-adjust the .conf files, you’ll need to restart nginx again.

Next you can test it with some simple software like VLC along with OBS or your churches streaming software or hardware encoder. You’ll need your RTMP feed to go to your server IP address which is seen on the home page of the instances of Lightsail. It’s on the bottom right above your server location. You can also set it to make it static at this point, but that will give it a new one that will not change. You’ll want that so you don’t always have to change your OBS or streaming software or hardware. To make a static IP just go to the instance by clicking the hyperlinked name and then choose networking from the options across the middle of the page. Then choose static IP on the left.

This image has an empty alt attribute; its file name is Screen-Shot-2020-05-01-at-1.22.42-PM.png
This image has an empty alt attribute; its file name is Screen-Shot-2020-05-01-at-1.25.47-PM.png

You should also set the firewall rules to allow port 1935. That’s the one that RTMP is on and we do that through the networking page under the IP information.

This image has an empty alt attribute; its file name is Screen-Shot-2020-05-03-at-7.40.06-AM.png

In OBS or your hardware encoder choose these options in the stream settings:

Service: Custom
Server: rtmp://<<ngnix server IP address>>/live
Stream Key: test

For a playback test use VLC or something that can play RTMP streams. Set it up as follows: Go to Network Stream, Network.

network URL: rtmp://<<ngnix server IP address>>/live/test

After we have that all running. We have to get stunnel so that facebook will work. We’ll go back to the command prompt from your server. Issue the following commands to get stunnel.

sudo apt-get install stunnel4 -y

Now we’ll have to change stunnel’s boot configuration, issue the following command:

sudo nano /etc/default/stunnel4

Change Enabled from 0 to 1. It should look like the following:

ENABLED=1

Next we have to edit the stunnel configuration file.

sudo nano /etc/stunnel/stunnel.conf

You’ll have to cut and paste this in its entirety. It should look like this:

pid = /var/run/stunnel4/stunnel.pid
output = /var/log/stunnel4/stunnel.log
setuid = stunnel4
setgid = stunnel4
# https://www.stunnel.org/faq.html
socket = r:TCP_NODELAY=1
socket = l:TCP_NODELAY=1
debug = 4
[fb-live]
client = yes
accept = 1936
connect = live-api-s.facebook.com:443
verifyChain = no

Then of course you’ll have to use ctrl-x to exit, and Y to save it as the original named file.

Next we have make it enabled after boot by doing the following:

sudo systemctl enable stunnel4.service

Now we have to restart stunnel because we changed the configuration files.

sudo systemctl restart stunnel4.service

Now since we changed the stunnel configuration and all we should restart NGINX for good measure.

sudo systemctl restart nginx

Everything should be up and running at this point. You might want to take a snapshot again here, because that way you can always fix anything else that goes wrong. Also if you want to further modify this for other purposes to make it better later you have a good jumping off point to create a new instance. 🙂

Because this is not limited to who can send a stream to it and it’s sitting exposed with port 1935 open, you might either want to delete the open port of 1935 in Lightsail when it’s not in use, or just shut it off when not in use. If you want to shut it off when not in use just issue the command “sudo systemctl stop nginx”. This way no one else can send it anything. When you want to start it again obviously issue “sudo systemctl restart nginx”. If you want to solve it a better way yet, you can find your IP address for your church and make it so that only people coming from your church’s IP address can stream to your server. You would have to add a few lines in the beginning of that rtmp section of the nginx.conf file. You add the “allow publish 000.000.000.000;” and “deny publish all;” below the “chunk_size 4096;” and above the “application live {“. You’ll have to put your locations IP address in that field where the zeros are in my example.

rtmp {

        server {

                listen 1935;
                chunk_size 4096;
                #below is IP for your streaming location
                allow publish 000.000.000.000;
                #below is so others can't use the server
                deny publish all;

                application live {

Remember that whenever you change the nginx.conf file you have to restart the service so that the changes take effect by using the command : sudo systemctl restart nginx

If you need more help, please email me tim@timstreams.com or find me on Facebook.

On about May 5th, As a note, I had my 12 year old run through this and try out my instructions. He’s never done anything like this at all. He is a gamer though and has used computers for years in schooling. It took him 1 hour and 2 minutes including when I made a mistake when setting up streamkeys and also with him giving me junk for minor spelling issues and unclear instructions. I’ve since fixed most of the points he helped me with. I’ll probably use his server to stream the Live church service Wednesday night.