Skip to content

Athlon1600/nginx-rtmp-server

Repository files navigation

Nginx RTMP Live Streaming Server

GitHub last commit GitHub Actions Workflow Status Top language

Self-host your own streaming server without relying on any external and expensive services (like Amazon IVS).

See a working demo here - https://nginx-rtmp.athlon1600.com/

🐳 Requirements

All you need is Docker.
On Linux, you can install it with just this one-liner:

curl -fsSL https://get.docker.com/ | sh

🚀 Deployment

Whether you are playing with this on your local computer, or hosting it on a real server, the steps are basically the same. Things do change a lot once you actually get thousands of users though.

Start by cloning this repository, and then start the services using Docker:

git clone https://github.com/Athlon1600/nginx-rtmp-server.git
cd nginx-rtmp-server
docker-compose up --build -d

and that is it!

Assuming you are doing this from your local computer, that should launch two services:

  • HTTP Nginx Server on port 8090: http://localhost:8090
  • RTMP Ingest Server on port 1935: rtmp://localhost:1935

🎥 Live-streaming to your server

Once the two services are up and running, you can now start streaming to your newly launched RTMP server at this endpoint:

rtmp://localhost:1935/live/{stream_key}

{stream_key} can be anything you want. In all the examples below we will be using test.

If you are using OBS, point your streaming settings to:

rtmp://localhost:1935/live/test

OBS Stream Settings

You can also stream any mp4-like video file using ffmpeg command:

ffmpeg -stream_loop -1 -nostdin -re -i "./video.mp4" -copy -f flv rtmp://localhost/live/test

📺 Viewing your live-stream with HLS

Every stream will produce .m3u8 playlist, that is then made accessible via HTTP protocol, and can then be consumed by any client that supports HLS protocol such as VLC media player, or your web-browser.

That playlist URL will look something like:

http://localhost:8090/hls/test/master.m3u8

Where test is a "stream key" for that particular stream.

To play it using VLC Media player:

VLC Media Player Open Network Stream VLC Media Player Network URL

Or you can play it in your web-browser with any HLS supporting video player such as:

🔒 Caddy Server

If you want HTTPS support out of the box, you should install and use Caddy web server:

wget -qO- https://raw.githubusercontent.com/Athlon1600/useful/master/caddy/caddy_linux_amd64.sh | bash

Next step is to update etc/Caddyfile configuration file, and then run:

caddy start --config ./etc/Caddyfile

Projects using this library

Links