This is a simple bash script how you can create an NGINX origin server where you can store HLS chunks and manifest files from a remote server using the HTTP PUT method.
My test scenario is a server running ffmpeg creating the HLS chunks and the manifest file pushing the content to a remote web server running NGINX. The script installs automatically NGINX and do the required changes in the NGINX configuration files using the SED command. The name of the script is origin.sh, you just need to clone it and run it.
In general the first part of the script is checking if the user input is a valid IP address or netmask and if it is or if it is left empty, it is adapting the scripts/origin_server
configuration file. The script is having 4 different functions:
nginx-install
updating the target system and installing the full NGINX packagedir-creation
- creates the specified in theorigin_server
configurationautodelete
- creates a crontab job every minute to check and delete in the defined directories files older than 1 minute.nginx_configuration
- which is inserting the specified user IP address or netmask in step #1, copying theorigin_server
configuration to/etc/nginx/sites-available
and creating a symbolic link of this file in/etc/nginx/sites-enabled
. It also increases the maximum upload limit to 50Mb and restarts the NGINX in case there aren't any errors in the configuration file, in order to apply the changes.
Please note that step#3 autodelete
is optional since most of the packagers are sending HTTP DELETE requests, to delete the old chunks and these requests are respected by the NGINX.
It sets the location of the NGINX log files to /var/log/nginx/origin_server
and defines the publish directory to /var/www/html/live/upload
for live content, /var/www/html/vod/upload
for VoD content and also the playback URL: /live/public
for live and /vod/public
for VoD content.
Please note that /live/public
is actually an alias of /var/www/html/live/upload
, the same applies for /vod/public
- alias to /var/www/html/vod/upload
so http://hostname/live/upload
should be used as a publish URL and http://hostname/live/public/
as a playback URL. Similarly http://hostname/vod/upload
is the publish URL and http://hostname/vod/public
is the playback URL.
The playback URLs are accepting GET requests from all the private networks and also from the initially defined by the user IP address or network. The publish URLs are accepting only PUT and DELETE HTTP requests.
I have also created a WIKI page where I have explained in details the commands and how you can harden the access to the origin server. So make sure to check my WIKI.
Please use Github Issues in case you spot a bug or have an idea how to optimize the scripts.