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
- How to Set Up HLS Streaming with Nginx
- How to Stream Live Video with OBS Studio to a Self-Hosted RTMP Server
- VPS Requirements for Media Streaming Servers
Browse more articles in Media & Streaming Servers.