Nginx-rtmp直播服务器编译配置

来源:互联网 发布:黑暗迪迦官方数据无限 编辑:程序博客网 时间:2024/06/15 12:31
编译

1、  需要的库nginx-rtmp-module,openssl,pcre,nginx。

2、  只需要在nginx运行.configure和make就可以,ningx的编译会自动去编译链接其他库的源码,不需要单独编译其他库。


配置与维护

1、  启动nginx的命令为”sudo  nginx的可执行文件” 

2、  修改配置文件后不重启nginx使配置生效的方法

(1)”sudo nginx的可执行文件 –t” 测试nginx的配置文件是否有语法错误

(2)”sudo nginx的可执行文件 –r reload”使更改后的配置文件生效。

3、  需要修改的配置文件只有nginx.conf。

4、  修改nginx-rtmp配置语法需要参考的资料

(1)在线官方资料

https://github.com/arut/nginx-rtmp-module/wiki/Examples

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

https://github.com/arut/nginx-rtmp-module/wiki/Directives

(2)nginx-rtmp-module源码目录下的test/nginx.conf文件

5、一些常用配置文件写法

(1)点播服务器

rtmp {
    server {
        listen 1935;
        application vod {
       play /var/flvs;
    }
   }
}

 

(2)直播服务器

rtmp {
    server {
    listen 1935;
     application live {
        live on;
    }
  }
}

 

(3)将远程服务器上的流拉到本地,播放时播放rtmp://本机IP/tv/maintv即可。

rtmp {
  server {
    listen 1935;
    application tv {
       live on;
       pull rtmp://cdn.example.com:443/programs/main name=maintv;
    }
 }
}

 

(4)将推到nginx服务器上的流转推到指定地址

rtmp {
  server {
    listen 1935;
     application tv {
       live on;
        push rtmp://cdn.example.com:443/programs/main;
     }
   }
}

 

(5)hls分发

rtmp {
  server {
    listen 1935;
    application tv {
      live on;
      hls on;
       hls_path /tmp/tv2;
      hls_fragment 15s;
      pull rtmp://tv2.example.com:443/root/new name=tv2;
    }
  }
}
 
http {
  server {
    listen 80;
    location /tv2 {
      alias /tmp/tv2;
    }
  }
}

 

(6)从其他服务器拉流转推到其他服务器

application myapp {
   live on; 
    pull rtmp://100.100.100.100:9023/live/zhejiang live=1 name=zhe static;
    on_publish http://127.0.0.1/on_publish2;
}
 
http {
  server {
    listen 80;
    location / on_publish2 {
       rewrite ^.*$ rtmp://192.168.10.10/app/name permanent;
    }
  }
}
注:在nginx里嵌入ffmpeg时要把ffmpeg放在/usr/bin目录下否则可能找不到
0 0