DIY streaming

It’s All Great To Have a custom video streaming solution but it’s expensive and when you are on a budget you want something that’s going to work but safely and reliably. It doesn’t have to be expensive like Live365 or even boxcast. I found the way to do it easily. Here’s how setup an account with AfterBurst. In fact this is how we are running our streaming for our stations right now online.

Now use Ubuntu 18.04 for an account KVM option.

Then use these commands.

apt-get update -y && apt-get dist-upgrade -y 
sudo apt-add-repository ppa:hda-me/nginx-stable
sudo apt-get update
apt-get install nginx brotli nginx-module-brotli nginx-module-rtmp 
apt-get install icecast2 -y
'
then mv /etc/nginx/nginx.conf /etc/nginx/nginx.conf.bak
then nano /etc/nginx/nginx.conf

Copy and paste the below information
user www-data;
pid /run/nginx.pid;
load_module modules/ngx_rtmp_module.so;
load_module modules/ngx_http_brotli_filter_module.so;
load_module modules/ngx_http_brotli_static_module.so;
worker_processes auto;
events {
    worker_connections 10240;
    multi_accept on;
}

rtmp {
    server {
        listen 1935; # Listen on standard RTMP port
        chunk_size 4000;

        application show {
            live on;
            # Turn on HLS
            hls on;
            hls_path /mnt/hls/;
            hls_fragment 3;
            hls_playlist_length 60;
            # disable consuming the stream from nginx as rtmp
            deny play all;
        }
    }
}

http {
    sendfile off;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 65;
    types_hash_max_size 2048;
    server_tokens off;
    proxy_max_temp_file_size 0;
    server_names_hash_bucket_size 64;
    server_name_in_redirect off;

    include /etc/nginx/mime.types;
    default_type application/octet-stream;

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
    ssl_prefer_server_ciphers on;
    gzip on;
    gzip_disable "msie6";

    gzip_vary on;
    gzip_proxied any;
    gzip_comp_level 6;
    gzip_buffers 16 8k;
    gzip_http_version 1.1;
    gzip_types *;

map $request_uri $redirect_fbclid {
    "~^(.*?)([?&]fbclid=[a-zA-Z0-9_-]+)$"  $1;
  }
    server {
    listen 443 ssl http2;
    server_name livestream.example.com;

    ssl_certificate           /etc/nginx/cert.crt;
    ssl_certificate_key       /etc/nginx/cert.key;
    ssl_client_certificate /etc/nginx/cloudflare.crt;
    ssl_verify_client off;


        location / {
            # Disable cache
            add_header 'Cache-Control' 'no-cache';

            # 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/dash+xml mpd;
                application/vnd.apple.mpegurl m3u8;
                video/mp2t ts;
            }

            root /mnt/;
        }

    }
server {
    listen 80;
    return 301 https://$host$request_uri;

}

server {

    listen 443 ssl http2;
    server_name listen.example.com;

    ssl_certificate           /etc/nginx/cert.crt;
    ssl_certificate_key       /etc/nginx/cert.key;
    ssl_client_certificate /etc/nginx/cloudflare.crt;
    ssl_verify_client off;

    gzip on;
    gzip_disable "msie6";

    gzip_vary on;
    gzip_proxied any;
    gzip_comp_level 6;
    gzip_buffers 16 8k;
    gzip_http_version 1.1;
    gzip_types *;

    location / {

      proxy_set_header        Host $host;
      proxy_set_header        X-Real-IP $remote_addr;
      proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header        X-Forwarded-Proto $scheme;

      # Fix the “It appears that your reverse proxy set up is broken" error.
      proxy_pass          http://localhost:8000;
      proxy_read_timeout  90;

      proxy_redirect      http://xxx.xxx.xxx.xxx:8000 https://listen.example.com;
    }
    if ( $redirect_fbclid ) {
      return 301 $redirect_fbclid;
    }

  }

}