您的位置:首页 > 运维架构 > Nginx

nginx+rtmp module搭建直播+录制环境

2016-05-09 19:41 597 查看
摘要: nginx+rtmp module

安装过程

1、将nginx和nginx-rtmp-module的源码包解压
PS:

nginx下载地址

http://nginx.org/en/download.html

nginx-rtmp-module网址
https://github.com/arut/nginx-rtmp-module

2、进入nginx的源代码目录,编译
./configure --add-module=<path-to-nginx-rtmp-module>

使用nginx 1.7.2

错误如下:

adding module in /home/andrew/Work/tools/nginx-rtmp-module

+ ngx_rtmp_module was configured

checking for PCRE library ... not found

checking for PCRE library in /usr/local/ ... not found

checking for PCRE library in /usr/include/pcre/ ... not found

checking for PCRE library in /usr/pkg/ ... not found

checking for PCRE library in /opt/local/ ... not found

./configure: error: the HTTP rewrite module requires the PCRE library.

You can either disable the module by using --without-http_rewrite_module

option, or install the PCRE library into the system, or build the PCRE library

statically from the source with nginx by using --with-pcre=<path> option.

需要安装PCRE或者不支持rewrite功能

./configure --add-module=<path-to-nginx-rtmp-module> --without-http_rewrite_module
make
make install

3、写一个测试配置文件

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;
}

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 {
rtmp_stat all;
rtmp_stat_stylesheet stat.xsl;
}
location /stat.xsl {
root /home/andrew/Work/tools/nginx-rtmp-module;
}

error_page   500 502 503 504  /50x.html;
location = /50x.html {
root   html;
}
}
}

rtmp {
server {
listen 1935;
chunk_size 4096;
application myapp {
live on;
}
}
}


nginx配置

worker_processes  1;
user root;
#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;
}

http {
include       mime.types;
default_type  application/octet-stream;

sendfile        on;
keepalive_timeout  18000;

server {
listen       80;
server_name  localhost;

location / {
root   html;
index  index.html index.htm;

client_body_temp_path  /usr/local/nginx/html/tmp;
}

location /stat {
rtmp_stat all;
rtmp_stat_stylesheet stat.xsl;
}
location /stat.xsl {
root /home/andrew/Work/tools/nginx-rtmp-module;
}

error_page   500 502 503 504  /50x.html;
location = /50x.html {
root   html;
}
}
}

rtmp {
server {
listen 1935;
chunk_size 4096;
application myapp {
live on;
record all;
record_path /tmp/;

recorder all {
record all;
record_suffix -%d-%b-%y-%T.flv;
}
}
}
}

启动nginx

/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

进入/usr/local/nginx/sbin目录,执行nginx

./nginx

打开浏览器输入http://ip可看到nginx已经启动的画面

使用ffmpeg推流到服务器

例如

./ffmpeg -re -i test2.flv -c:a copy -y -f flv rtmp://192.168.40.128:1935/myapp/stream1

访问http://192.168.40.128/stat,看到以下统计信息

nginx结束

./nginx-sstop或者./nginx-squit

一个是强制快速结束,一个是温柔结束.

注释:

192.168.40.128为测试内网IP
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  nginx+rtmp module