Knowledge Base

Another template for nginx.conf

apt-get update
git clone https://github.com/sergey-dryabzhinsky/nginx-rtmp-module.git
apt-get --assume-yes install build-essential libpcre3 libpcre3-dev libssl-dev zlib1g-dev ffmpeg
wget http://nginx.org/download/nginx-1.17.8.tar.gz
tar -xf nginx-1.17.8.tar.gz
cd nginx-1.17.8
./configure --with-http_ssl_module --add-module=../nginx-rtmp-module
make -j 1
sudo make install
echo "
worker_processes  auto;
events {
	worker_connections  1024;
}

rtmp {
server {
	listen 1935;
	chunk_size 4000;
	application live {
		live on;
		exec_push ffmpeg -i rtmp://127.0.0.1/live/\$name -force_key_frames source -c:v libx264 -b:v 250k -preset veryfast -c:a copy -s 320x180 -pix_fmt yuv420p -f flv rtmp://127.0.0.1/hls/\$name-180p -force_key_frames source -c:v libx264 -b:v 700k -preset veryfast -c:a copy -s 640x360 -pix_fmt yuv420p -f flv rtmp://127.0.0.1/hls/\$name-360p -force_key_frames source -c:v libx264 -b:v 1500k -preset veryfast -c:a copy -s 960x540 -pix_fmt yuv420p -f flv rtmp://127.0.0.1/hls/\$name-540p -c:v copy -c:a copy -f flv rtmp://127.0.0.1/hls/\$name-orig 2>>/var/log/ffmpeg-\$name.log;
	allow play 127.0.0.1;
	deny play all;
	}

	application hls {
		live on;
		hls on;
		hls_path /mnt/hls/;
		deny play all;
		hls_variant -180p BANDWIDTH=346000 RESOLUTION=320x180;
		hls_variant -360p BANDWIDTH=796000 RESOLUTION=640x360;
		hls_variant -540p BANDWIDTH=1596000 RESOLUTION=960x540;
		hls_variant -orig BANDWIDTH=2596000 RESOLUTION=1280x720;
		}
	}
}
	http {
	sendfile off;
	tcp_nopush on;
	directio 512;
	default_type application/octet-stream;

	server {
		listen 80;
		location / {
		add_header 'Cache-Control' 'no-cache';
		add_header 'Access-Control-Allow-Origin' '*' always;
		add_header 'Access-Control-Expose-Headers' 'Content-Length';
		if (\$request_method = 'OPTIONS') {
			add_header 'Access-Control-Allow-Origin' '*';
			add_header 'Access-Control-Max-Age' 1728000;
			add_header 'Content-Type' 'text/plain charset=UTF-8';
			add_header 'Content-Length' 0;
			return 204;
			}
                        types {
				application/dash+xml mpd;
				application/vnd.apple.mpegurl m3u8;
				video/mp2t ts;
				}
			root /mnt/;
			}
		}
	}
" > /etc/nginx/nginx.conf
Table of Contents