示例可用于Ubuntu 18/19/20 + Nginx平台。
- 安装nginx模块:nginx-rtmp-module
- 配置 /etc/nginx/nginx.conf:
rtmp {
server {
listen 1935;
notify_method get;
chunk_size 4000;
# video on demand for flv files
application vod {
play /var/www/flvs;
}
# video on demand for mp4 files
application vod2 {
play /var/www/mp4s;
}
# HLS
application stream {
live on;
hls on;
hls_path /var/www/html/hls;
hls_fragment 5s;
allow play all;
publish_notify on;
on_publish http://localhost/auth;
record off;
}
# RTMP
application live {
live on;
}
}
}
- 以nginx default网站为例,配置/etc/nginx/sites-available/default:
# This URL provides RTMP statistics in XML
location /stat {
rtmp_stat all;
rtmp_stat_stylesheet /stat.xsl;
}
location /stat.xsl {
# XML stylesheet to view RTMP stats.
# Copy stat.xsl wherever you want
# and put the full directory path here
root /var/www/html;
}
location /stream {
types {
application/vnd.apple.mpegurl m3u8;
video/mp2t ts;
}
root /tmp;
add_header Cache-Control no-cache;
}