Skip to content

Set up my own Stream Server

Daniel Neto edited this page Aug 5, 2022 · 29 revisions

Install Nginx and Nginx-RTMP. Understanding the limitations and possible options

Source Information :

Additional Information: I'll be installing it on Ubuntu 18.04

1. You need to have AVideo installed :

For new installations :

Ubuntu 16.04: https://github.com/WWBN/AVideo/wiki/How-to-install-LAMP,-FFMPEG-and-Git-on-a-fresh-Ubuntu-16.x-For-AVideo-Platform-version-4.x-or-newer

Ubuntu 18.04: https://github.com/WWBN/AVideo/wiki/How-to-install-LAMP,-FFMPEG-and-Git-on-a-fresh-Ubuntu-18.x-for-AVideo-Platform-version-4.x-or-newer

Ubuntu 20.04: https://github.com/WWBN/AVideo/wiki/How-to-install-LAMP,-FFMPEG-and-Git-on-a-fresh-Ubuntu-20.x-for-AVideo-Platform-version-11.x-or-newer

Making it clear

  • Install the Apache webserver for the streamer and encoder
  • Install Nginx webserver/live server
  • Both web servers Apache/Nginx can coexist on the same server (Virtual or dedicated) just make sure they have different ports, we recommend you to follow the default ports.

2. Install Nginx and Nginx-RTMP

sudo apt-get install -y build-essential libpcre3 libpcre3-dev zlib1g zlib1g-dev libssl-dev php7.2-xml

sudo mkdir ~/build && cd ~/build && sudo git clone git://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 --add-module=../nginx-rtmp-module

sudo make && sudo make install

sudo mkdir /usr/local/nginx/ssl/ && sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /usr/local/nginx/ssl/nginx.key -out /usr/local/nginx/ssl/nginx.crt

sudo /etc/init.d/apache2 restart && sudo mkdir /HLS && sudo mkdir /HLS/live

Additional Notes:

For Ubuntu 18.04 you need the php7.2-xml , Ubuntu 16.04 php7.0-xml

For Ubuntu 18.04 I recommend using version 1.16.1 at the least. Older versions may result in errors during the installation

The packages zlib1g zlib1g-dev are installed to avoid error the HTTP gzip module requires the zlib library.

3. Enable Nginx RTMP statistics and set up RTMP support

cd /usr/local/nginx/html && sudo wget https://raw.githubusercontent.com/WWBN/AVideo/master/plugin/Live/install/stat.xsl

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

Open the config file, and replace [AVideoURL] with your domain name or IP

sudo nano /usr/local/nginx/conf/nginx.conf

The result should look something like this:

image

IMPORTANT NOTE: NGINX does not recognize HTTPS URLs, even if your site does support SSL, you will have to use the HTTP URL. On point 10 of this guide, you will find how to configure the SLL.

4. Install Live Plugin and Live Chat plugin

Access to your AVideo website, log in with your admin account. Browse to Plugins, and install the tables for the plugins Live (Live) and LiveChat (LiveChat), then enable them.

image

Note: The Live Chat plugin is deprecated and will be removed next version. In case you're reading this in the future, this feature could be missing. We strongly recommend upgrading to Chat2 (Chat2). You can find it here: https://youphp.tube/plugins/

5. Setup variables on Plugin manager. Understanding the listed option :

image

button_title: The text that gonna be displayed on the live's button .

server: The RTMP root url

playerServer: Where is the server gonna be listening

stats: Url where to check/monitor/display the streams stats

Enable/Disable RVD: Feature to playback streams. This feature requires hls_playlist_length . More information at the Extra Settings ( NGINX.CONF ) section ( at the bottom )

disableGifThumbs If enabled the AVideo script will automatically generate GifThumbs from streams.

useAadaptiveMode To use this feature you will need the HLS plugin https://youphp.tube/marketplace/, and configure live transcoding; We have a guide here : https://github.com/WWBN/AVideo/wiki/Adaptive-Bitrates-on-Livestream

experimentalWebcam Experimental feature for webcam

doNotShowLiveOnVideosList If enabled, live streams will not be displayed on the welcome page .

doNotProcessNotifications In case you have the Notification plugin but you don't wanna send a notification, you may want to select this option. Default disabled .

hls_path: The path we have set earlier on the nginx.conf for the hls fragments. Default /HLS/live

6. Make the chat-server.php run

Execute the command line ( on the server's terminal ) that you have on your plugin section. This will initialize the connection of your chat plugin .

image

nohup php /var/www/YouPHPTube/plugin/LiveChat/chat-server.php &

Then press Ctrl+C

7. Start Nginx

sudo /usr/local/nginx/sbin/nginx

Note: If you're getting this type of ''errors'' when you start Nginx, that means your Nginx is already running. Is not an error or issue.

image

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

8. Test RTMP module on http://[your address]:[8080]/stats

Check if the server is running. We can check that by accessing the stat page we indicated on our plugin. Default: http://YourIP:8080/stat

9. in case you use an HTTPS connection you may need to Enable secure WebSocket

sudo nano /etc/apache2/mods-available/proxy.conf

Add : ProxyPass /wss/ ws://127.0.0.1:8888/

Make the file looks like this :

image

Enable the module and restart apache

sudo a2enmod proxy_wstunnel

/etc/init.d/apache2 restart

10. Configure SSL certificate for the Nginx config

I'm assuming that you already have a signed certificate. Now you need to include it on the nginx.conf

sudo nano /usr/local/nginx/conf/nginx.conf

Find the HTTP section. You will need to indicate the SSL port that you wanna use. Avoid using 443, since it's already used by Apache. In this case, we will use port 444 .

Lines to be added :

listen 444 SSL;

ssl_certificate /etc/letsencrypt/live/demo.avideo.com/fullchain.pem;

ssl_certificate_key /etc/letsencrypt/live/demo.avideo.com/privkey.pem;

server_name demo.avideo.com;

Replace demo.avideo.com with your path to the certificate or your domain name. The result should look like this :

image

11. Extra Settings ( NGINX.CONF )

these settings are not required, but I'll share them with you and explain some of the features .

image

I'll not explain everything. If you need to understand some parameters, remove them or change them take a look at the source information : https://github.com/arut/nginx-rtmp-module/wiki/Directives

Important things that you may wanna consider are the latency ( stream delay ). You may wanna consider adding:

hls_fragment 2s; ( make sure your keyframe is double the video's framerate video )

max_streams 32; The maximum streams you wanna allow

hls_nested on; This is important if you wanna enable DVR. Will create a sub-directory for each streamer.

hls_playlist_length 120m; This feature is for DVR . How many minutes do you want NGINX to save for playback. All the fragments will be saved under the ID streamer.

hls_cleanup on; Clear the HLS fragment at the restart of the Nginx server. NGINX will handle it.

Those are the most important feature to consider. After changing the config , don't forget to restart nginx . sudo /usr/local/nginx/sbin/nginx -s stop && sudo /usr/local/nginx/sbin/nginx

Clone this wiki locally