1 . Log into the instance via SSH
2 . Update the apt sources lists and upgrade the software already installed on the instance:
apt update && apt upgrade -y
3 . All required packages for the basic server configuration are available via APT. Install nginx and the required packages:
apt install build-essential libpcre3 libpcre3-dev libssl-dev nginx libnginx-mod-rtmp ffmpeg -y
4 . Open the Nginx configuration file /etc/nginx/nginx.conf in a text editor:
nano /etc/nginx/nginx.conf
And add the following lines at the end of the configuration file:
rtmp {
server {
listen 1935;
chunk_size 4096;
notify_method get;
application live {
on_publish http://localhost/auth;
live on;
#Set this to "record off" if you don't want to save a copy of your broadcasts
record all;
# The directory in which the recordings will be stored
record_path /var/www/html/recordings;
record_unique on;
}
}
}
This sets up the live streaming server as well as recording of the streams. These will be stored in the directory /var/www/html/recordings of the instance.
5 . Create the directory for recordings and make it writeable to the web server software:
mkdir -p /var/www/html/recordings
chown -R www-data:www-data /var/www/html/recordings/
7 . Open the file /etc/nginx/sites-enabled/default in a text editor and add a location block to the server configuration:
nano /etc/nginx/sites-enabled/default
libnginx-mod-rtmp does not support authentication by default. To avoid that anybody knowing the stream key may broadcast media, copy / paste the following content into the server configuration block, under the server_name block, to setup a basic authentication mechanism. It will ask for a password when streaming. If the password is not correct, the user will see a 401 - Unauthorized message:
location /auth {
if ($arg_pwd = 'a_secret_password') {
return 200;
}
return 401;
}
Replace a_secret_password with a secret password of your choice which authenticates against the server for broadcasting streams.
8 . Restart the Nginx web server:
systemctl restart nginx.service
netstat -an | grep 1935