下载Nginx,nginx 1.7.11.3 Gryphon版本
地址
2、配置nginx
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
rtmp_auto_push on;
#RTMP服务
rtmp{
server{
listen 1935; #服务端口
chunk_size 4096; #数据传输块的大小
#rtmp点播配置,访问方式:rtmp://127.0.0.1:1935/vod/xxx.mp4
application vod {
play ./vod; #点播视频存放目录,里面放一个xxx.mp4可以直接播放
}
#rtmp协议直播推流
application live {
live on;
record all;
record_path ./rec; # 保存路径
#record_max_size 1K;
#append current timestamp to each flv
record_unique on;
#publish only from localhost
#allow publish 127.0.0.1;
#deny publish all;
}
# HLS协议直播推流
application hls {
live on; #开启rtmp直播
hls on; #开启hls支持
wait_video on; #第一个视频帧发送前禁用音频
hls_path ./m3u8File; #文件保存路径,需要先创建,不然执行推流会报错
hls_fragment 5s; #用来设置每一个块的大小。默认是5秒。只能为整数
hls_playlist_length 30s; #设置播放列表的长度,单位是秒,听说设置成3秒延迟低点
hls_nested off; #默认是off。打开后的作用是每条流自己有一个文件夹
hls_cleanup off; #不清理ts , on|off 默认是开着的,是否删除列表中已经没有的媒体块
#hls_continuous: #on|off 设置连续模式,是从停止播放的点开始还是直接跳过
}
}
}
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server {
listen 9090;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
#hls点播地址
location /hls {
types {
application/vnd.apple.mpegurl m3u8;
#或 application/x-mpegURL
video/mp2t ts;
}
alias ./m3u8File; #点播视频文件(.ts;.m3u8)存放位置
expires -1;
add_header Cache-Control no-cache; #跨域支持,不然网页播放不了
add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Headers "Origin, X-Requested-With, Content-Type, Accept";
add_header Access-Control-Allow-Methods "GET, POST, OPTIONS";
}
# 直播状态监听
location /stat{
rtmp_stat all;
rtmp_stat_stylesheet stat.xsl;
}
location /stat.xsl{
root ./nginx-rtmp-module-master;