Skip to content

Set up my own Stream Server

Daniel Neto edited this page Oct 25, 2024 · 29 revisions

Install Nginx RTMP: Standalone Installation Guide

Source Information:

Note: This guide recommends using Ubuntu 24.04 or newer for optimal performance and compatibility.

1. Prerequisites

Before installing Nginx RTMP, ensure your server is up-to-date. This guide is designed for Ubuntu 24.04 but is adaptable for other versions.

2. Install Nginx and Nginx-RTMP

Run the following commands to install the required packages and set up Nginx RTMP:

sudo apt-get update -y && sudo apt-get upgrade -y
sudo apt-get install -y build-essential libpcre3 libpcre3-dev zlib1g zlib1g-dev libssl-dev
sudo mkdir ~/build && cd ~/build
sudo git clone https://github.com/arut/nginx-rtmp-module.git
sudo wget http://nginx.org/download/nginx-1.16.1.tar.gz && sudo tar xzf nginx-1.16.1.tar.gz
cd nginx-1.16.1
sudo ./configure --with-http_ssl_module --with-http_stub_status_module --with-http_auth_request_module --add-module=../nginx-rtmp-module
sudo make && sudo make install

3. Configure Nginx RTMP

  1. Download the RTMP statistics stylesheet:
cd /usr/local/nginx/html
sudo wget https://raw.githubusercontent.com/WWBN/AVideo/master/plugin/Live/install/stat.xsl
  1. Set up the RTMP configuration by replacing the existing Nginx configuration file:
sudo mv /usr/local/nginx/conf/nginx.conf /usr/local/nginx/conf/nginx.conf.old
cd /usr/local/nginx/conf/
sudo wget https://raw.githubusercontent.com/WWBN/AVideo/master/plugin/Live/install/nginx.conf
  1. Open and edit the configuration file to add your domain name:
sudo nano /usr/local/nginx/conf/nginx.conf

4. Add Your Domain Name in nginx.conf

Before proceeding with SSL setup, ensure that your domain name is correctly set in the nginx.conf file:

  1. In the server block under the http section, add your domain name as follows:
server {
    listen 8080;
    server_name yourdomain.com; # Replace with your actual domain name

    location /live {
        root /HLS; # HLS root path
        # Additional location configurations as needed...
    }
}

Replace yourdomain.com with your actual domain name. This step is crucial as Let's Encrypt will use this domain to validate and issue the SSL certificate.

5. Create Directories for HLS

Ensure that the directories for HLS segments exist:

sudo mkdir /HLS && sudo mkdir /HLS/live

These directories will store HLS fragments generated by the Nginx RTMP server.

6. Obtain SSL Certificate Using Let's Encrypt

Once your domain is correctly set in the nginx.conf file, you can proceed to obtain an SSL certificate:

  1. Install Certbot for Nginx:
sudo apt install -y certbot python3-certbot-nginx
  1. Run Certbot to obtain and configure the SSL certificate:
sudo certbot --nginx --nginx-server-root /usr/local/nginx/conf --no-redirect

Certbot will read the domain name from the nginx.conf file and issue an SSL certificate for it. Make sure your domain's DNS is correctly configured to point to your server's IP address before running Certbot.

7. Update SSL Configuration to Use Port 8443

After obtaining the certificate, modify the SSL configuration in nginx.conf to use port 8443:

  1. Edit the nginx.conf file:
sudo nano /usr/local/nginx/conf/nginx.conf
  1. Add or modify the SSL block to look like this:
server {
    listen 8443 ssl;
    ssl_certificate /etc/letsencrypt/live/yourdomain.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/yourdomain.com/privkey.pem;
    server_name yourdomain.com;

    location /live {
        root /HLS; # HLS root path
        # Additional location configurations as needed...
    }
}

Ensure yourdomain.com matches the domain name you used with Certbot.

8. Start and Manage Nginx

Start Nginx with the following command:

sudo /usr/local/nginx/sbin/nginx

Notes:

  • If Nginx is already running, you may receive a message indicating it. This is not an error.
  • To stop Nginx:
sudo /usr/local/nginx/sbin/nginx -s stop
  • To restart Nginx:
sudo /usr/local/nginx/sbin/nginx -s stop && sudo /usr/local/nginx/sbin/nginx

9. Test the RTMP Module

Check the RTMP statistics page to ensure the server is running correctly:

http://[your IP or domain]:8080/stat

This page displays the status of your RTMP server and active streams.

Clone this wiki locally