How to Set Up Nginx RTMP for Live Video Streaming

Nginx's RTMP module lets you run your own live video streaming server — accepting a stream from broadcasting software (like OBS Studio) and distributing it to viewers, without depending on a third-party platform.

What RTMP Streaming Enables

Real-Time Messaging Protocol (RTMP) is the standard protocol broadcasting software uses to send a live video stream to a server — your own RTMP server can then re-distribute that stream to viewers, giving you full control over your live streaming infrastructure.

Prerequisites

  • Ubuntu 22.04/24.04 VPS: 4 vCPU, 4 GB RAM minimum (more for transcoding multiple quality levels)

Step 1 — Install Nginx with the RTMP Module

sudo apt install libnginx-mod-rtmp -y

Step 2 — Configure the RTMP Block

sudo nano /etc/nginx/nginx.conf
rtmp {
    server {
        listen 1935;
        chunk_size 4096;

        application live {
            live on;
            record off;
        }
    }
}

Step 3 — Restart Nginx

sudo nginx -t && sudo systemctl restart nginx

Step 4 — Allow the RTMP Port

sudo ufw allow 1935/tcp

Step 5 — Configure Broadcasting Software

See How to Stream Live Video with OBS Studio to a Self-Hosted RTMP Server for the client-side configuration, pointing at:

rtmp://YOUR_SERVER_IP/live

Step 6 — Enable HLS Output for Browser Playback

application live {
    live on;
    hls on;
    hls_path /var/www/hls;
    hls_fragment 3;
    hls_playlist_length 60;
}

Converts the incoming RTMP stream into HLS (HTTP Live Streaming), playable directly in web browsers via a standard video player — see How to Set Up HLS Streaming with Nginx for the full HLS-specific configuration.

Serving the HLS Output

server {
    listen 80;
    location /hls {
        root /var/www;
        add_header Cache-Control no-cache;
        add_header Access-Control-Allow-Origin *;
    }
}

Restricting Who Can Publish a Stream

application live {
    live on;
    allow publish 127.0.0.1;
    deny publish all;
}

By default, anyone who discovers your RTMP URL could start streaming to it — restrict publishing to specific trusted IPs, or implement a stream key validation mechanism for broader authorized access.

Recording Streams (Optional)

application live {
    live on;
    record all;
    record_path /var/recordings;
}

Common Errors

OBS connects but no video appears for viewers — verify the HLS output path is correctly configured and being written to, and that the web server can actually serve files from that path.

High CPU usage during streaming — if transcoding to multiple quality levels, this is expected; monitor and size your VPS accordingly (see VPS Requirements for Media Streaming Servers).

Continue Reading

Browse more articles in Media & Streaming Servers.

  • nginx rtmp, live streaming server, self hosted streaming, rtmp setup
  • 0 A felhasználók hasznosnak találták ezt
Hasznosnak találta ezt a választ?

Kapcsolódó cikkek

How to Install Jellyfin Media Server on a VPS

Jellyfin is a free, open-source media server — a fully self-hosted alternative to Plex or...

How to Install Plex Media Server on a VPS

Plex is a widely-used media server platform offering a polished interface and broad device...

How to Set Up HLS Streaming with Nginx

HTTP Live Streaming (HLS) delivers video by breaking it into small segments served over standard...

How to Install Icecast for Internet Radio Streaming

Icecast is a lightweight, open-source streaming server purpose-built for audio — ideal for...

How to Install PeerTube (Self-Hosted YouTube Alternative)

PeerTube is a decentralized, open-source video hosting platform — letting you run your own...