安装nginx
下载ngnix源码
git clone https://github.com/nginx/nginx.git
git clone https://github.com/arut/nginx-rtmp-module.git
编译安装
./configure --add-module=../nginx-rtmp-module-master
make
sudo make install
默认安装路径为/usr/local/nginx,运行./sbin/nginx
打开浏览器在地址栏输入:localhost,如果显示Welcome to nginx,说明安装成功了
配置rtmp服务
打开./conf/nginx.conf ,添加RTMP的配置
worker_processes 1;
events {
worker_connections 1024;
}
rtmp { #RTMP服务
server {
listen 6666; #//服务端口
chunk_size 4096; #//数据传输块的大小
application vod { #//点播服务
play /opt/video/vod; #//视频文件存放位置。
}
application live{ #第一处添加的直播字段
live on;
}
}
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
location / {
root html;
index index.html index.htm;
}
location /stat { #第二处添加的location字段。
rtmp_stat all;
rtmp_stat_stylesheet stat.xsl;
}
location /stat.xsl { #第二处添加的location字段。
root /usr/local/nginx/nginx-rtmp-module/;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
配置目录/opt/video/vod为存放视频文件的位置,放一个视频文件test.mp4用于测试
打开视频播放软件,播放地址填写rtmp://localhost:6666/vod/test.mp4
live是直播服务,如果打算弄多个频道的直播就可以live_2、live_2名字任意。第二处就是添加两个location字段,字段的内容请直接看文件吧。