Starting A Live Stream Server from Scratch

 Intro

This tutorial will set up a live stream server from scratch with Docker, Nginx, Git & Github, SSH, and Coffee. All you need is:

- A Computer connected to the Internet

- 1 hour

- $9 dollars

- Some programming knowledge (e.g how to npm install and ssh?)

Initial Setup

1. Choose a provider, I prefer dynadot.com where you can buy .top domain for less than $5, but you can find others. 

2. Purchase hosting. vpsag.com has offers such that $3.5 gets you 2 GB RAM, 20GB Storage Server in EU :) Select Ubuntu 20.04 and build a server. Note down the IP.

3. Using IP from step 2,  Update hosting. Add "A Record" with IP as value. Doing this early gives it time to propagate.

Local Setup

We will be using WebRTC Video/Audio Broadcast by Gabriel Tanner 👏. 

4. Clone this repository to your local machine.

5. npm install then node server

6. Visit localhost:4000/broadcast.html to start broadcasting. On a different tab/browser visit localhost:4000 to live stream.

Host Setup

Our host will use Git, Nginx Server, and Docker as well as SSH.

7. After logging in, create this folder /var/repo/live-stream.git and open it.

8. Type git init --bare to initialize an empty repository.

9. Create/Open this file /var/repo/live-stream.git/hooks/post-receive and add the following contents:

#!/bin/sh
Unset GIT_INDEX_FILE
git --work-tree=/var/www/live-stream.top --git-dir=/var/repo/live-stream.git checkout -f

cd /var/www/live-stream.top/
chown -R :www-data .
chmod -R 777 .
npm install

docker build --tag webrtcvideobroadcast .
docker stop $(docker ps -aqf "name=webrtcvideobroadcast")
docker run -d -p 4000:4000 --restart unless-stopped --name webrtcvideobroadcast webrtcvideobroadcast

10. Create the following folder and leave empty

/var/www/live-stream.top

11. Type the following: 

sudo chmod +x /var/repo/live-stream.git/hooks/post-receive

12. Install LetsEncrypt and Nginx.

sudo apt install nginx
sudo apt install certbot python3-certbot-nginx

13. Create the Nginx server block for your application /etc/nginx/sites-enabled/live-stream

server {
server_name live-stream.top;
location / {
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $http_host;
proxy_pass "http://127.0.0.1:4000";

}
}

14. Test your nginx configuration: sudo nginx -t and restart it sudo systemctl restart nginx. You can use docker here too 👺

15. Secure domain with Certbot. Ensure you redirect HTTP to HTTPS.

certbot --nginx -d live-stream.top
certbot renew --dry-run

15. On Local Machine open where you cloned this GitHub repo via Terminal and add remote and push:

git remote add test ssh://root@live-stream.top:22/var/repo/live-stream.git
git push test master

The terminal will show the build as it happens until docker starts your image. You can visit your website and see it in action. 

Conclusion

With great power comes great responsibility. If you are having challenges, please reach out I will be glad to assist.


Comments

Popular Posts