How to Set Up a Reliable Streaming Server on CentOS 8 Using Nginx and the RTMP Module
Forget overpriced streaming services—empower your own infrastructure by transforming CentOS 8 into a powerful, customizable streaming server that scales with your needs.
Streaming video content is no longer a luxury—it’s become essential for businesses, educators, event organizers, and creators alike. But utilizing third-party platforms can get expensive quickly and limits your control over how content is delivered and managed. The solution? Build your own reliable, cost-effective streaming server.
In this guide, you’ll learn how to set up a robust streaming server on CentOS 8 using Nginx paired with the RTMP module. CentOS 8’s stability and long-term support make it an ideal base for hosting your own streaming infrastructure.
Why Set Up Your Own Streaming Server?
- Cost-saving: Avoid recurring fees from commercial streaming providers.
- Control: Manage your video content delivery without vendor restrictions.
- Customization: Tailor encoding and delivery options to exactly what you need.
- Scalability: Start small but scale as your audience grows.
Prerequisites
- A CentOS 8 server with root or sudo access.
- Basic familiarity with Linux command line.
- A firewall configured to allow TCP ports used for HTTP and RTMP.
Step 1: Update Your System Packages
Before we dive in, update your packages to ensure you have the latest dependencies:
sudo dnf update -y
sudo dnf install -y epel-release
sudo dnf groupinstall "Development Tools" -y
Step 2: Install Nginx with RTMP Module
CentOS 8’s default Nginx package does not include the RTMP module, so you need to compile Nginx from source with the RTMP module enabled.
Install Required Dependencies
sudo dnf install -y gcc make pcre-devel openssl-devel wget unzip
Download Nginx and RTMP Module Source Code
Visit nginx.org for the latest stable version number of Nginx or use the example below:
NGINX_VERSION=1.22.1
wget http://nginx.org/download/nginx-$NGINX_VERSION.tar.gz
tar zxvf nginx-$NGINX_VERSION.tar.gz
git clone https://github.com/arut/nginx-rtmp-module.git
Compile Nginx with RTMP Module
cd nginx-$NGINX_VERSION
./configure --with-http_ssl_module --add-module=../nginx-rtmp-module
make
sudo make install
By default, make install
will place Nginx in /usr/local/nginx
.
Step 3: Configure Nginx for Streaming
Navigate to /usr/local/nginx/conf/
and open nginx.conf
in your favorite editor:
sudo nano /usr/local/nginx/conf/nginx.conf
Replace or add this configuration at the bottom of the file:
rtmp {
server {
listen 1935; # standard RTMP port
chunk_size 4096;
application live {
live on;
record off;
# You can set an authentication mechanism here if needed.
}
}
}
http {
include mime.types;
default_type application/octet-stream;
server {
listen 8080;
server_name localhost;
location / {
root html;
index index.html index.htm;
}
# Serve HLS fragments produced by the RTMP module if streaming HLS
location /hls {
types {
application/vnd.apple.mpegurl m3u8;
video/mp2t ts;
}
root /tmp;
add_header Cache-Control no-cache;
}
}
}
This configuration:
- Listens for RTMP streams on port 1935.
- Defines an application
live
where streams can be pushed. - Opens an HTTP interface on port 8080, which can serve HLS (HTTP Live Streaming) output if configured later.
Step 4: Start Your Nginx Server
Start nginx using:
sudo /usr/local/nginx/sbin/nginx
To reload configuration later:
sudo /usr/local/nginx/sbin/nginx -s reload
Check if it’s listening on port 1935:
sudo ss -tulnp | grep 1935
You should see nginx listening on that port.
Step 5: Stream Content to Your Server Using OBS Studio
Open Broadcaster Software (OBS) is a free tool widely used for streaming.
- Open OBS.
- Go to Settings > Stream
- Set:
- Stream Type: Custom Streaming Server
- URL:
rtmp://your_server_ip/live
- Stream Key: Any stream key you want (e.g.,
mystream
)
- Click Start Streaming. OBS will push video content via RTMP.
Step 6 (Optional): Enable HLS (HTTP Live Streaming)
To allow viewers to watch through HTTP using HLS protocols (very common in web players), modify your nginx.conf
further inside the application live
block like this:
application live {
live on;
record off;
hls on;
hls_path /tmp/hls;
hls_fragment 3;
}
Create the directory:
mkdir -p /tmp/hls
chmod -R 755 /tmp/hls
Reload nginx:
sudo /usr/local/nginx/sbin/nginx -s reload
You can now watch your stream in a web player supporting HLS like video.js by pointing it to:
http://your_server_ip:8080/hls/mystream.m3u8
Replace mystream
with whatever stream key you used.
Final Thoughts & Security Recommendations
By running your own streaming server on CentOS 8, you:
- Keep full ownership of your video content.
- Eliminate middlemen fees & restrictions.
- Gain powerful customization abilities according to your bandwidth and scale needs.
Security Tips:
- Consider setting up firewall rules to only allow trusted IPs or use authentication modules for securing publishing streams.
- Use SSL/TLS certificates on HTTP interfaces if serving HLS over HTTPS (with additional reverse proxy setups).
- Monitor logs regularly
/usr/local/nginx/logs/
.
With these steps, you have created a reliable foundation for delivering live video streaming directly from CentOS 8 using open-source tools. Customize it further depending on whether you want VOD capabilities, adaptive bitrate streaming, or integrating CDN layers down the line!
Happy streaming! 🚀