Code Monkey home page Code Monkey logo

nginx-rtmp's Introduction

nginx-rtmp

NGINX based RTMP server using nginx-rtmp-module. For full HD streaming, it is recomended to run the server off of a min 1Gbps capable NIC. Debian is the only supported linux distro.

Synopsys

This is a basic RTMP streaming server that ingests RTMP streams and outputs video to a web server for Internet browser use within the local NAT layer. It utilizes NGINX with the nginx-rtmp-module to host the RTMP server itself and to host the web server for the flash based player. Streams are dumped to a file @ “/home/gmstv/announcements”. HLS is implimented to enable playback on Apple mobile devices.

A good guide for how to make a (basic) server like this can be found at the OBS Forums

Usage

Repo organisation

  • NGINX Builds - Mirror for recent builds of NGINX
  • usr/local/nginx - NGINX webserver code
  • usr/local/nginx/html/bin-debug - Test RTMP Player exclusively for debug use
  • usr/local/nginx/html/player - (Recomended) Stylised Player for end user
  • usr/local/nginx/html/player2 - Unstylised Player for end user

Initial Setup Tutorial

Install and Configuration

  • Obtain and install from source the latest versions of both nginx and the nginx-rtmp-module following the instructions on the nginx-rtmp-module wiki. (Debian is similar enough to Ubuntu, as it is based on the basic Debian framework)
  • Git clone the contents of this repo to the default NGINX directory /usr/local/nginx

Generating init Script and Starting Server

  • Make file /etc/init.d/nginx with contents:
### BEGIN INIT INFO
# Provides:          nginx
# Required-Start:    $all
# Required-Stop:     $all
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: starts the nginx web server
# Description:       starts nginx using start-stop-daemon
### END INIT INFO

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/local/sbin/nginx
NAME=nginx
DESC=nginx

test -x $DAEMON || exit 0

# Include nginx defaults if available
if [ -f /etc/default/nginx ] ; then
    . /etc/default/nginx
fi

set -e

. /lib/lsb/init-functions

case "$1" in
  start)
    echo -n "Starting $DESC: "
    start-stop-daemon --start --quiet --pidfile /usr/local/nginx/logs/$NAME.pid 
        --exec $DAEMON -- $DAEMON_OPTS || true
    echo "$NAME."
    ;;
  stop)
    echo -n "Stopping $DESC: "
    start-stop-daemon --stop --quiet --pidfile /usr/local/nginx/logs/$NAME.pid 
        --exec $DAEMON || true
    echo "$NAME."
    ;;
  restart|force-reload)
    echo -n "Restarting $DESC: "
    start-stop-daemon --stop --quiet --pidfile 
        /usr/local/nginx/logs/$NAME.pid --exec $DAEMON || true
    sleep 1
    start-stop-daemon --start --quiet --pidfile 
        /usr/local/nginx/logs/$NAME.pid --exec $DAEMON -- $DAEMON_OPTS || true
    echo "$NAME."
    ;;
  reload)
      echo -n "Reloading $DESC configuration: "
      start-stop-daemon --stop --signal HUP --quiet --pidfile /usr/local/nginx/logs/$NAME.pid 
          --exec $DAEMON || true
      echo "$NAME."
      ;;
  status)
      status_of_proc -p /usr/local/nginx/logs/$NAME.pid "$DAEMON" nginx && exit 0 || exit $?
      ;;
  *)
    N=/etc/init.d/$NAME
    echo "Usage: $N {start|stop|restart|reload|force-reload|status}" >&2
    exit 1
    ;;
esac

exit 0
  • Give all execute privileges:

sudo chmod +x /etc/init.d/nginx

  • Add script to default runlevels:

sudo /usr/sbin/update-rc.d -f nginx defaults

  • Start server:

sudo /etc/init.d/nginx start (Can be restarted by replacing start with restart, or stop to shutdown)

Open RTMP Port via iptables

  • Set iptables firewall rule opening the default RTMP port: (1935)

sudo iptables -A INPUT -p tcp --dport 1935 --jump ACCEPT; sudo iptables-save

  • Save current iptables config to file for later use:

iptables-save > /etc/firewall.conf

  • Make bash script /etc/init.d/iptables-open-rtmp:
#!/bin/bash
iptables-restore -n < /etc/firewall.conf
  • Make /etc/init.d/iptables-open-rtmp executable:

sudo chmod 775 /etc/init.d/iptables-open-rtmp

  • Add /etc/init.d/iptables-open-rtmp to rc2.d so it will auto-execute upon reboot:

sudo update-rc.d iptables-open-rtmp defaults

Done! Happy streaming, serving and tinkering!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.