Build a Live Streaming Server with Nginx, FFmpeg, and OpenResty

This guide walks through selecting streaming protocols, preparing a high‑performance server, installing OpenResty, compiling the nginx‑ts module, configuring Nginx for RTMP/HLS/DASH, pushing streams with FFmpeg or OBS, and applying security and stability best practices.

Open Source Tech Hub
Open Source Tech Hub
Open Source Tech Hub
Build a Live Streaming Server with Nginx, FFmpeg, and OpenResty

Introduction

Live streaming can use the low‑latency RTMP protocol or the widely compatible HTTP‑based HLS protocol; the choice depends on real‑time requirements and device compatibility.

Server Environment Setup

Select a performant cloud server and install required tools such as Nginx, FFmpeg, and OpenResty.

OpenResty and Module Installation

Download OpenResty:

wget https://openresty.org/download/openresty-1.21.4.3.tar.gz

Clone the nginx‑ts module:

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

Install FFmpeg (refer to external tutorial).

Dynamic Compilation and Configuration

apt-get install libreadline-dev libncurses5-dev libpcre3-dev \
    libssl-dev perl make build-essential
./configure --prefix=/opt/openresty --with-luajit --without-http_redis2_module \
    --with-http_iconv_module --add-dynamic-module=/root/nginx-ts-module
make -j4
sudo make install

Key configuration file ( nginx.conf) loads the TS module and defines HTTP and RTMP locations, e.g.:

# vim /opt/openresty/nginx/conf/nginx.conf
error_log  logs/error.log;
pid        logs/nginx.pid;
load_module "/opt/openresty/nginx/modules/ngx_http_ts_module.so";

http {
    server {
        listen 8777;
        location /publish/ {
            ts;
            ts_hls path=/var/media/hls segment=10s;
            ts_dash path=/var/media/dash segment=10s;
            client_max_body_size 0;
        }
        location /play/ {
            add_header Cache-Control no-cache;
            add_header 'Access-Control-Allow-Origin' '*';
            types { application/x-mpegURL m3u8; application/dash+xml mpd; video/MP2T ts; video/mp4 mp4; }
            alias /var/media/;
        }
    }
}

Create media directories:

cd /var && mkdir media
cd media && mkdir hls dash

FFmpeg Stream Push

Push a stream from a source to the server:
ffmpeg -re -i rtmp://liteavapp.qcloud.com/live/liteavdemoplayerstreamid \
    -bsf:v h264_mp4toannexb -c copy -f mpegts http://127.0.0.1:8777/publish/sintel
If port 8777 is occupied, use an alternative port.

Public RTMP Test Addresses

rtmp://liteavapp.qcloud.com/live/liteavdemoplayerstreamid   (smooth)
rtmp://ns8.indexforce.com/home/mystream                (some lag)
rtmp://mobliestream.c3tv.com:554/live/goodtv.sdp       (slow)

Client Playback Example

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Live Streaming Demo</title>
</head>
<body>
    <video data-dashjs-player autoplay src="http://127.0.0.1:8777/play/dash/sintel/index.mpd" controls></video>
</body>
</html>

Playback Screenshots

OBS Streaming

When FFmpeg is not used directly, OBS Studio can push the stream to http://127.0.0.1:8777/publish/sintel .

OBS Studio is a free, open‑source Windows application that captures video, audio, and graphics, encodes with H.264/X264 and AAC, and supports GPU‑accelerated game capture.

OBS Solution Details

Download nginx‑rtmp‑module:

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

Compile and load the module similarly to the TS module, adding

load_module "/opt/openresty/nginx/modules/ngx_rtmp_module.so";

to nginx.conf.

Streaming flow: OBS → nginx‑rtmp → nginx‑ts.

This allows Windows users to stream without invoking FFmpeg directly.

Security and Stability Optimizations

Protect the live system by configuring access controls, enabling SSL encryption, and setting up load balancing.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

live streamingNGINXffmpegRTMPOpenResty
Open Source Tech Hub
Written by

Open Source Tech Hub

Sharing cutting-edge internet technologies and practical AI resources.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.