Setting up a video streaming server using Nginx with the RTMP module on Ubuntu 22.04 allows you to stream video content over RTMP (Real-Time Messaging Protocol). Here's a step-by-step guide:
Prerequisites:- Ubuntu 22.04 Server: Set up a clean Ubuntu 22.04 server.
- Root or Sudo Access: Ensure you have root or sudo privileges.
-
Update and Upgrade:
sudo apt update sudo apt upgrade
-
Install Required Dependencies:
sudo apt install build-essential libpcre3 libpcre3-dev libssl-dev zlib1g-dev ffmpeg
-
Download Nginx Source Code:
mkdir ~/nginx-rtmp cd ~/nginx-rtmp wget http://nginx.org/download/nginx-1.21.5.tar.gz tar -zxvf nginx-1.21.5.tar.gz
Replace
1.21.5
with the latest stable version available at the time of installation. -
Download Nginx-RTMP Module:
git clone https://github.com/arut/nginx-rtmp-module.git
-
Compile Nginx with RTMP module:
cd nginx-1.21.5 ./configure --with-http_ssl_module --add-module=../nginx-rtmp/nginx-rtmp-module make sudo make install
-
Create a Configuration File:
sudo nano /usr/local/nginx/conf/nginx.conf
Add the RTMP configuration block:
worker_processes auto; events {} rtmp { server { listen 1935; chunk_size 4096; application live { live on; record off; } } } http { server { listen 8080; location / { # Configure a simple web page or player to view the stream root html; index index.html; } } }
-
Start Nginx:
sudo /usr/local/nginx/sbin/nginx
-
Stream from OBS (Open Broadcaster Software):
- Open OBS, go to Settings -> Stream.
-
Choose Custom service with RTMP as the service and set the Server and Stream Key to
rtmp://your_server_ip/live
.
-
Watch the Stream:
-
Use a video player (like VLC) or a web-based player to watch the stream by accessing
http://your_server_ip:8080
.
-
Use a video player (like VLC) or a web-based player to watch the stream by accessing
This basic setup enables you to stream content to the server using the RTMP protocol and view the stream through a player or browser.
Remember, for production environments, consider setting up security measures, such as authentication, to control access to the streaming server. Additionally, configure firewalls and monitor the server for optimal performance.