How to Use the NGINX RTMP Module to Setup a Streaming Server

  Use code KB4KDO0L9 to receive a 10% recurring discount on any server.

One of the most common video streaming protocols is an HLS Streaming Server. HLS is an adaptive streaming technology which allows you to stream media content that is tailored to the user's device and network conditions for the best streaming performance. 

HLS and RTMP can be easily integrated with the Nginx web server using the Nginx RTMP module. In this tutorial, we'll show you how to setup an HLS live streaming server on Ubuntu.

See Also: ServerMania Media Streaming Server Solutions

What is Nginx RTMP?

Nginx RTMP is an Nginx module which allows you to add RTMP and HLS streaming to your media server. Previously, the RTMP and HLS modules were seperate Nginx modules, but they can now all be added to Nginx as a single module.

DOWNLOAD NOW: server management calendar

Increase server uptime and security with our recommended monthly server management tasks calendar.

Server Requirements

  • Ubuntu OS (May work on other Operating Systems with command modifications)
  • Minimum 2GB RAM
  • Disk space as required for any media files
  • ServerMania Hybrid or Dedicated Server

Installation Instructions

Step 1: Login via SSH to the server

Login as root or a user with sudo access on the server. If you are using a user with sudo access, then add sudo before each command in the tutorial:

ssh root@server-ip

Step 2: Download required software

Start by updating the apt repository:

apt-get update

If this is a new server, you should consider updating the system software:

apt-get Upgrade

We'll then install the required software:

apt-get install -y git build-essential ffmpeg libpcre3 libpcre3-dev libssl-dev zlib1g-dev

Step 3: Clone Module

git clone

Step 4: Download Nginx

Copy the latest download link from the Nginx website and decompress the files:

tar -xf nginx-1.17.6.tar.gz
cd nginx-1.17.6

Step 5: Configure Nginx

./configure --prefix=/usr/local/nginx --with-http_ssl_module --add-module=../nginx-rtmp-module
make -j 1
make install

Step 6: Configure Nginx

rm /usr/local/nginx/conf/nginx.conf
nano /usr/local/nginx/conf/nginx.conf

Copy the following contents into the file and save it:

worker_processes auto;
events {
worker_connections 1024;

# RTMP configuration
rtmp {
server {
listen 1935; # Listen on standard RTMP port
chunk_size 4000;

application show {
live on;
# Turn on HLS
hls on;
hls_path /mnt/hls/;
hls_fragment 3;
hls_playlist_length 60;
# disable consuming the stream from nginx as rtmp
deny play all;

http {
sendfile off;
tcp_nopush on;
directio 512;
default_type application/octet-stream;

server {
listen 8080;

location / {
# Disable cache
add_header 'Cache-Control' 'no-cache';

# CORS setup
add_header 'Access-Control-Allow-Origin' '*' always;
add_header 'Access-Control-Expose-Headers' 'Content-Length';

# allow CORS preflight requests
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Max-Age' 1728000;
add_header 'Content-Type' 'text/plain charset=UTF-8';
add_header 'Content-Length' 0;
return 204;

types {
application/dash+xml mpd;
application/ m3u8;
video/mp2t ts;

root /mnt/;

Step 7: Start Nginx

Start Nginx


Step 8: Start Streaming

This server can stream from a variety of sources including a static file, webcam, etc.

We previously installed ffmpeg. We'll start streaming example-vid.mp4 to our http://localhost/show/stream

ffmpeg -re -i example-vid.mp4 -vcodec libx264 -vprofile baseline -g 30 -acodec aac -strict -2 -f flv rtmp://localhost/show/stream

Step 9: Integrate into Player

The stream can now be integrated into a javascript HLS player as per your requirements. 

Deploying An Nginx RTMP Server

If you have any questions about deploying a new Nginx RTMP or HLS server, you should consider booking a free consultation. We can help you choose the right server hardware for your media streaming project.

Now that you've learned about creating an Nginx RTMP server, why not read about: What is RTMP?

About The Author

generic avatar icon

Complete Digital Server Solutions For All

Bare Metal

Dedicated Servers

A single tenant, physical server allowing you full access to its resources.


Hybrid Servers

Virtualized server platform hosted on enterprise-grade physical servers.

Affordable & Secure

Cloud Servers

High-performance and highly-available infrastructure, delivering a reliable, secure, and scalable solution.

    • You can stream from a mobile phone by using the phone as a source in OBS. Lookup “using xxx as a webcam over wifi on yyy” where xxx is your phone and yyy is your operating system. There are several apps.

  • How to catch streaming events, for example, that the streaming has not yet begun, or that the straming has already ended?

  • Mark, thanks for the write up – clear and easy to follow. I’m running into a 403 “forbidden” error however when running the ffmpeg command. I have a small mp4 that I’m feeding into “rtmp://localhost/show/stream” but the file downloads instead of showing up as video in my browser (I have an hls extension installed in my chrome browser on a different computer) and the error.log for nginx says ‘directory index of “/mnt/” is forbidden’… I’ve googled for a solution but am coming up short on this. Any help at all would be appreciated.

  • Nice guide. But I’m unable to find the address for viewer (to watch the stream). I understand that the config sets output to HLS.
    But am unable to find the correct address.
    Please add this last part to the guide.