user www-data; worker_processes 1; pid /run/nginx.pid; include /etc/nginx/modules-enabled/*.conf; include /etc/nginx/conf.d/*.conf; events { worker_connections 768; # multi_accept on; } http { ## # Basic Settings ## sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 65; types_hash_max_size 2048; # server_tokens off; # server_names_hash_bucket_size 64; # server_name_in_redirect off; include /etc/nginx/mime.types; default_type application/octet-stream; server { listen 80; listen [::]:80; #Server_name you.ip.he.re # include snippets/snakeoil.conf; keepalive_timeout 70; gzip off; root /var/www/html; # Add index.php to the list if you are using PHP index index.php index.html low.html low.php live.html live.php med.php med.html; location / { location ~* \.m3u8$ { add_header Cache-Control no-cache; } add_header Access-Control-Allow-Origin *; # First attempt to serve file, then as directory, then a 404. try_files $uri $uri/ =404; } # pass PHP scripts to FastCGI server location ~ \.php$ { include snippets/fastcgi-php.conf; # # With php-fpm (or other unix sockets): fastcgi_pass unix:/var/run/php/php7.2-fpm.sock; # # With php-cgi (or other tcp sockets): # fastcgi_pass 127.0.0.1:9000; } # deny access to .htaccess files, if Apache's document root concurs with nginx's one #location ~ /\.ht { # deny all; #} # This provides RTMP statistics in XML at http://your-server-address/stat location /stat { rtmp_stat all; rtmp_stat_stylesheet stat.xsl; # auth_basic "Restricted Content"; # auth_basic_user_file /etc/nginx/.htpasswd; } # XML stylesheet to view RTMP stats. Copy stat.xsl wherever you want and put the full directory path here location /stat.xsl { root /var/www/html/; } # Control interface (extremely useful, but can also boot people from streams so we put basic auth in front of it - # see https://github.com/arut/nginx-rtmp-module/wiki/Control-module for more info #location /control { # you'll need a htpasswd auth file, that's outside the scope of this doc but any apache one will work #auth_basic "Restricted Content"; auth_basic_user_file /etc/nginx/.htpasswd; rtmp_control all; #} #creates the http-location for our full-res desktop HLS stream "http://my-ip/live/my-stream-key/ index.m3u8" location /live { # root /var/livestream/hls; alias /var/livestream/hls; expires -1; autoindex on; autoindex_localtime on; # CORS setup # set $sent_http_accept_ranges bytes; add_header 'Cache-Control' 'no-cache'; add_header Cache-Control no-cache; add_header 'Access-Control-Allow-Origin' '*' always; add_header 'Access-Control-Expose-Headers' 'Content-Length'; # allow CORS preflight requests # 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/vnd.apple.mpegurl m3u8; application/dash+xml mpd; video/mp2t ts; } } #creates the http-location for our mobile-device HLS stream - "http://my-ip/low/my-stream-key/index.m3u8" location /low { # Disable cache add_header 'Cache-Control' 'no-cache'; # CORS setup add_header 'Access-Control-Allow-Origin' '*' always; add_header 'Access-Control-Expose-Headers' 'Content-Length'; # allow CORS preflight requests 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/vnd.apple.mpegurl m3u8; } alias /var/livestream/low; } #creates the http-location for our medium 360 HLS stream - "http://my-ip/med/my-stream-key/index.m3u8" location /med { # Disable cache add_header 'Cache-Control' 'no-cache'; # CORS setup add_header 'Access-Control-Allow-Origin' '*' always; add_header 'Access-Control-Expose-Headers' 'Content-Length'; # allow CORS preflight requests 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/vnd.apple.mpegurl m3u8; } alias /var/livestream/med; } #######enable nginx_status below######## location /nginx_status { # Enable Nginx stats stub_status on; # Only allow access from your IP e.g 1.1.1.1 or localhost # #allow YOURIPADDRESSHERE; #allow 127.0.0.1; #allow YOUROTHERIPADDRESSHERE; #allow YOURNEEDEDIPADDRESSESHERE; # Other request should be denied #deny all; allow all; } location /live.html { root /var/www/html/; #if you want the video sites to be seen by other people then allow all below allow all; #allow YOURIPADDRESSESHERE; #allow YOURIPADDRESSESHERE; } location /med.html { root /var/www/html/; #if you want the video sites to be seen by other people then allow all below allow all; #allow YOURIPADDRESSESHERE; #allow YOURIPADDRESSESHERE; } location /low.html { root /var/www/html/; #if you want the video sites to be seen by other people then allow all below allow all; #allow YOURIPADDRESSESHERE; #allow YOURIPADDRESSESHERE; } ###### } } ## # Logging Settings ## access_log /var/log/nginx/access.log; error_log /var/log/nginx/error.log; ## # Gzip Settings ## #gzip on; # gzip_vary on; # gzip_proxied any; # gzip_comp_level 6; # gzip_buffers 16 8k; # gzip_http_version 1.1; # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript; ## # Virtual Host Configs ## #include /etc/nginx/conf.d/*.conf; #include /etc/nginx/sites-enabled/*; } rtmp { server { listen 1935; chunk_size 8192; ###if you want to protect this from being used by anyone else ###you should enter your IPs you stream from in here ###you can add as many as you want in this format ###below is IP for somewhere? #allow publish 000.000.000.000; #below is IP for someserver? #allow publish 000.000.000.000; #allow publish 127.0.0.1; ###The below makes it so no one else can publish on it other than above #deny publish all; application live { live on; interleave off; meta on; wait_key on; wait_video on; idle_streams off; sync 300ms; session_relay on; allow publish all; allow play all; max_connections 1000; ## == FORWARD STREAM (OPTIONAL) == ## # === FACEBOOK below == == This sends it through STUNNEL #push rtmp://127.0.0.1:1936/rtmp/YOUR-FACEBOOK-KEY; # == == TWITCH RE-STREAM == == # push rtmp://live-ams.twitch.tv/app/LIVESTREAM_KEY; # == == YOUTUBE FOR CCFRED RE-STREAM == == #push rtmp://a.rtmp.youtube.com/live2/YOUR YOUTUBE KEY; #== == MIXER.com RE-STREAM == == # push rtmp://ingest-ams.mixer.com:1935/beam/LIVESTREAM_KEY; publish_notify off; # play_restart off; #on_publish http://your-website/on_publish.php; #on_play http://your-website/on_play.php; #on_record_done http://your-website/on_record_done.php; ## == HLS == ## hls off; # hls_nested on; #hls_path /var/livestream/hls/live; #hls_base_url http://; #hls_playlist_length 60s; #hls_fragment 10s; #hls_sync 100ms; #hls_cleanup on; ## == DASH == ## dash off; # dash_nested on; #dash_path /var/livestream/dash; #dash_fragment 10s; #dash_playlist_length 60s; # dash_cleanup on; push rtmp://localhost/hls; #creates the downsampled or "trans-rated" mobile video stream as a 400kbps, 480x360 sized video, this one is a 360p feed exec ffmpeg -i rtmp://localhost:1935/$app/$name -acodec copy -c:v libx264 -preset veryfast -profile:v baseline -vsync cfr -vf scale=-2:360,setdar=16:9 -b:v 400k -bufsize 400k -threads 0 -r 30 -f flv rtmp://localhost:1935/low/${name}; #### creates Medium HLS feed This one is a 720p feed. This one is basically a copy of above but with modified scale exec ffmpeg -i rtmp://localhost:1935/$app/$name -acodec copy -c:v libx264 -preset veryfast -profile:v baseline -vsync cfr -vf scale=-2:720,setdar=16:9 -b:v 800k -bufsize 800k -threads 0 -r 30 -f flv rtmp://localhost:1935/med/${name}; } application hls { live on; allow play all; hls on; hls_type live; hls_nested on; hls_path /var/livestream/hls; hls_cleanup on; hls_sync 100ms; hls_fragment 10s; hls_playlist_length 60s; hls_fragment_naming system; } ##### Medium stream This one I set at 5 second fragment length just to test it out, this tells where to put the Medium size feed files. application med { allow play all; live on; hls on; hls_nested on; hls_path /var/livestream/med; hls_fragment 5s; } #creates our "mobile" lower-resolution HLS videostream from the ffmpeg-created stream and tells where to put the #HLS video manifest and video fragments application low { allow play all; live on; hls on; hls_nested on; hls_path /var/livestream/low; hls_fragment 10s; } } }