Debug 发表于 2019-6-25 03:46:16

基于宝塔nginx安装Nginx-rtmp-module搭建hls直播

本帖最后由 Debug 于 2020-4-15 17:14 编辑

主要是参考 https://www.bt.cn/bbs/thread-16118-1-1.html 帖子。

第一步,修改/www/server/panel/install/nginx.sh文件,找到 Install_Configure 部分。在每个./configure 后面插入增加模块编译语句:
./configure --add-module=/www/server/nginx_plus/nginx-rtmp-module

第二步,进入命令会话工具,执行git clone https://github.com/arut/nginx-rtmp-module /www/server/nginx_plus/语句,直到100%完成。

第三步,接着输入安装nginx脚本语句:
sh /www/server/panel/install/nginx.sh install 1.8
其中install 后的1.8为你要安装或切换的版本号。比如你已经安装了1.14版本的nginx,那么这里可以填1.8或其他版本号。如果你还没安装过。可以选择自己需要的版本。

直到安装编译完成。然后输入入nginx -V 检查编译时候完整:

看到rtmp关键模块后就表示模块安装成功。注意,安装成功后就不要使用宝塔后台的NGINX切换版本功能了(该功能位置请参考看第三步的截图),官方会拉取服务器的脚本执行,这样rtmp模块就会消失在新的nginx版本配置中。


第四步,在/www/server/nginx/conf下建立一个 rtmp.conf 的文件。创建如下内容:
rtmp_auto_push on;
rtmp {
    server {
      listen 1935;
      ping 30s;
      chunk_size 4000;
      notify_method get;

      application hls {
            live on;
            hls on;
            hls_path /www/tmp/hls;
            hls_sync 100ms;
            hls_fragment 5s;
      }
      application live {
                        live on;
      }
      # Video on demand
      #application vod {
      #    play /www/tmp/Videos;
      #}
      # Video on demand over HTTP
      #application vod_http {
      #    play http://localhost:8080/vod/;
      #}
    }
}第五步,在/www/server/nginx/conf下建立一个 hls.conf 的文件。创建如下内容:

server {
    listen8080;
    location /hls {
      # Serve HLS fragments
      types {
            application/vnd.apple.mpegurl m3u8;
            video/mp2t ts;
      }
      root html;
      expires -1;
    }
}注意:这里这是创建一个测试的播放入口。如果不需要特定测试入口,可以忽略此步。


第六步,打开/www/server/nginx/conf 下的nginx.conf文件,在events的花括号后面插入 include rtmp.conf 。修改内容如下
userwww www;
worker_processes auto;
error_log/www/wwwlogs/nginx_error.logcrit;
pid      /www/server/nginx/logs/nginx.pid;
worker_rlimit_nofile 51200;

events
    {
      use epoll;
      worker_connections 51200;
      multi_accept on;
    }
include rtmp.conf;第七步,打开/www/server/nginx/conf 下的nginx.conf文件,在include /www/server/panel/vhost/nginx/*.conf; 前面插入 include hls.conf 。修改内容如下
server
    {
      listen 888;
      server_name phpmyadmin;
      index index.html index.htm index.php;
      root/www/server/phpmyadmin;

      #error_page   404   /404.html;
      include enable-php.conf;

      location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
      {
            expires      30d;
      }

      location ~ .*\.(js|css)?$
      {
            expires      12h;
      }

      location ~ /\.
      {
            deny all;
      }

      access_log/www/wwwlogs/access.log;
    }
    include hls.conf;
include /www/server/panel/vhost/nginx/*.conf;
}以上安装完成,其他配置优化请自行处理吧。


cheani_08 发表于 2019-12-16 15:47:03

楼主 你的第二步:git 后面的地址应该改为 /www/server/nginx_plus/nginx-rtmp-module
要不然你第一步的往./configure 添加的 --add-module=/www/server/nginx_plus/nginx-rtmp-module是识别不到的

Debug 发表于 2019-6-25 03:50:14

补充说明:
1、如果第5步不执行,第7步也不需要的。
2、同时记得进入宝塔后台的安全面板中开启1935端口。
3、如果还有上一层防火墙的,还要增加1935端口映射,这里就不展开了。根据自身情况处理吧。

痞子哥 发表于 2019-6-25 10:12:30

这类帖子应该要加精啊 @大炮运维V587

宝塔用户_nrpsar 发表于 2019-8-10 13:16:01

好东西 支持一下

zk3151463 发表于 2019-9-3 16:33:57

照这个文档搭建成功了,不知道咋接收流呀,怎么对流截图

Debug 发表于 2019-9-11 14:30:42

rtmp.conf 和 hls.conf中有对应配置
推流地址 比如公网IP是 11.11.11.11 那么推流地址就是 rtmp://11.11.11.11:1935,流名自定义
拉流地址 http://11.11.11.11:8080/hls/流名

特卖云 发表于 2019-12-6 08:41:24

没找到Install_Configure

特卖云 发表于 2019-12-6 08:51:52

zk3151463 发表于 2019-9-3 16:33
照这个文档搭建成功了,不知道咋接收流呀,怎么对流截图

用阿里云播放器

glenlau 发表于 2019-12-29 11:02:22

找不到Install_Configure   我想搭一个流媒体服务器,里面还有共享云的服务,
Nginx + rtmp + ffmpeg 有没安装过且成功的朋友,分享下教程,谢谢

Xeath 发表于 2019-12-29 15:07:47

宝塔用户_bjhoqp 发表于 2019-12-29 11:02
找不到Install_Configure   我想搭一个流媒体服务器,里面还有共享云的服务,
Nginx + rtmp + ffmpeg 有 ...

ffmpeg 可以用 RPM Fusion 仓库提供的包进行安装。官网有提供安装和启用仓库的教程。https://rpmfusion.org/Configuration/
我有个自己编写的 ffmpeg 编译脚本,但是只是对 CentOS 8 有用。
rtmp 模块可以做成 nginx 的动态模块,再用 load_module 引入即可。
具体 GitHub 上面有一篇文章,而且还是拿 rtmp 来做说明。这里说明一下,rtmp 的代码已经默认支持编译为动态模块。
https://gist.github.com/undirectlookable/2a39cc85b16e2218f162
另外如果 make 版本过高,编译 rtmp 模块会出错,需要修改一下 Makefile 前行忽略错误。

温岭三中 发表于 2020-1-6 22:23:54

搞不定,有没有更详细的文档?

乡村名师韦成继 发表于 2020-1-17 19:39:19

折腾一天了,还是装不了

乡村名师韦成继 发表于 2020-2-5 00:42:39

如图,已安装rtmp-module 成功,nginx配置也成功了,接下来怎么配置和优化流直播?

乡村名师韦成继 发表于 2020-2-5 00:44:57

到这里不知道怎么配置了
页: [1] 2
查看完整版本: 基于宝塔nginx安装Nginx-rtmp-module搭建hls直播