worker_processes auto;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;

events {
	worker_connections 1024;
}

http {
	include       mime.types;
	default_type  application/octet-stream;

	sendfile        on;
	tcp_nopush      on;
	keepalive_timeout  65;

	# Small cache control for HLS/DASH files
	server {
		listen       8080;
		server_name  localhost;

		# Serve a simple index if desired
		location / {
			root   /usr/share/nginx/html;
			index  index.html index.htm;
		}

		# HLS fragments and playlists are written to /tmp/hls by the rtmp module
		location /hls {
			types {
				application/vnd.apple.mpegurl m3u8;
				video/mp2t ts;
			}
			root /tmp;
			add_header Cache-Control no-cache;
			add_header Access-Control-Allow-Origin *;
			# don't log every fragment request
			access_log off;
		}

		# DASH manifest and segments (if dash is enabled) will be in /tmp/dash
		location /dash {
			types { application/dash+xml mpd; }
			root /tmp;
			add_header Cache-Control no-cache;
			add_header Access-Control-Allow-Origin *;
			access_log off;
		}

		# RTMP status (requires nginx-rtmp compiled with the stat module)
		location /stat {
			rtmp_stat all;
			rtmp_stat_stylesheet stat.xsl;
		}

		location /stat.xsl {
			root /etc/nginx; # you can place stat.xsl next to this nginx.conf or adjust path
		}
	}
}

rtmp {
	server {
		listen 1935; # RTMP listen port
		chunk_size 4096;

		# Simple access log for rtmp
		access_log /var/log/nginx/rtmp_access.log;

		# Live application for ingest (publish) and HLS/DASH output
		application live {
			live on;
			# disable recording
			record off;

			# HLS settings
			hls on;
			hls_path /tmp/hls;
			hls_fragment 4s;
			hls_playlist_length 30s;
			# keep fragments for a short while (optional)
			hls_cleanup on;

			# DASH (MPEG-DASH) output
			dash on;
			dash_path /tmp/dash;
			dash_fragment 4s;

			# allow publish/play from anywhere by default; lock this down in production
			allow publish all;
			allow play all;
		}

	}
}

# End of configuration

