I am an absolute beginner with NGINX and RTMP module. I am working on a project which involves a live streaming app. I want to link this Nginx rtmp server to my django server which runs on port 8000. This is what I made up my nginx.conf file after going through multiple tutorials. What I understood from following the tutorials is that application is endpoint in rtmp so i put the url next to it, also I understand that hls video will be stored in the folder path that I provide along push/hls_path. I have a doubts now, do I need to define two applications(as it done) for start stream and stop stream or they can be clubbed together into one application. Please clarify my doubts and correct me.
Nginx configuration for RTMP upstream and HLS downstream
worker_processes auto;
events {
worker_connections 1024;
}
# RTMP configuration
rtmp {
server {
listen 1935; # Listen on standard RTMP port
chunk_size 4000;
application rtmp://localhost/api/livevideostreams/startstream {
# Live status
live on;
# Turn on HLS
hls on;
hls_fragment 3;
hls_playlist_length 60;
# disable consuming the stream from nginx as rtmp
deny play all;
# Push the stream to the local HLS application
push rtmp://localhost:1935/api/livevideostreams/hls_live/;
}
application rtmp://localhost:1935/api/livevideostreams/stopstream {
# Live status
live off;
# Turn on HLS
hls on;
hls_fragment 3;
hls_playlist_length 60;
# disable consuming the stream from nginx as rtmp
deny play all;
# Push the stream to the local HLS application
push rtmp://localhost:1935/api/livevideostreams/hls_live/;
}
}
}
application hls {
live on;
# Only accept publishing from localhost.
# (the `app` RTMP ingest application)
allow publish 127.0.0.1;
deny publish all;
deny play all;
# Package streams as HLS
hls on;
hls_path rtmp://localhost:1935/api/livevideostreams/hls_live/;
hls_nested on;
hls_fragment_naming system;
hls_datetime system;
}
http {
sendfile off;
tcp_nopush on;
directio 512;
default_type application/octet-stream;
server {
listen 8080;
location http://localhost:1935/api/livevideostreams/hls_live/; {
# 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/dash+xml mpd;
application/vnd.apple.mpegurl m3u8;
video/mp2t ts;
}
root /mnt/;
}
}
}