Linux Java 服务器搭建-Nginx 添加 rtmp 模块安装及配置及遇到的问题(八)

第一步需要安装nginx

具体过程参考https://blog.csdn.net/qq_39526250/article/details/80608850

#查看nginx端口

#ps -ef | grep nginx

查看模块

#/usr/local/nginx/sbin/nginx -V

显示(可能有所不同,注意保存自己的):

configure arguments:  --with-http_stub_status_module --with-http_ssl_module

第二步安装编译rtmp模块

从官方地址拉下源码:https://github.com/arut/nginx-rtmp-module 
保存在一个临时目录下:/home/nginx_rtmp 

#tar -zxvf v1.1.11.tar.gz


在nginx 源代码目录下运行:

注意:是在nginx的源代码路径下运行不是在安装后的目录

将进入源码路径 #cd /usr/local/nginx-1.8.0

  新配置信息在原本基础上增加模块(先查出来原来的模块)


执行#./configure --prefix=/usr/local/nginx  --add-module=/home/nginx_rtmp/nginx-rtmp-module-1.1.11 --with-http_stub_status_module --with-http_ssl_module 
执行#make


注意:--with-http_stub_status_module --with-http_ssl_module  后面这个是在第一步中查到自己的已有模块


安装已经结束,下面来看配置。

在nginx安装目录下先复制一份默认的配置文件出来:

cd /usr/local/nginx/conf
cp nginx.conf live_rtmp.conf

编辑live_rtmp.conf如下:

#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 {
    server {
        listen 1935;
        chunk_size 4000;
        # TV mode: one publisher, many subscribers
        application mylive {
            live on;
            hls on;
            hls_path /home/hls;
   
        }
    }
}
http {
    server {
        listen       8080;
        # This URL provides RTMP statistics in XML
        location /stat {
            rtmp_stat all;
            # Use this stylesheet to view XML as web page
            # in browser
            rtmp_stat_stylesheet stat.xsl;
        }
        location /stat.xsl {
            # XML stylesheet to view RTMP stats.
            # Copy stat.xsl wherever you want
            # and put the full directory path here
            root /usr/local/nginx/html/;
        }
        location /hls {
            # Serve HLS fragments
            types {
                application/vnd.apple.mpegurl m3u8;
                video/mp2t ts;
            }
            root /home;
            add_header Cache-Control no-cache;
        }
   }
}

验证配置文件正确性:

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

配置文件说明: 


1、hls开启后产生的m3u8文件会存在hls_path下,播放端调用404的时候先去看看m3u8有没有生成。 
2、stat.xsl要从nginx-rtmp的源代码根目录中考出来,考到配置的那个文件夹:

cp /home/nginx-rtmp-module-1.1.11/stat.xsl /usr/local/nginx/html/

3、验证的时候遇到个报错:

nginx: [emerg] unknown directive “rtmp” in xxxxx

这问题由两个方面造成,先确保安装rtmp模块的时候没有报错,其次是配置文件的编码最好是ASCII text,可以使用file nginx.conf指令查看一下。我的问题是第一个,安装的时候有报错:

报了大量的   $'\r': command not found

回忆了一下犯了个错误,我是在windows下git拉下来考到服务器上的,中间文件换编码了。。。。切记切记。。。。。要直接从linux git clone下来再安装。。。。 
重新安装rtmp之后解决了这个问题。

4、./configure: error: SSL modules require the OpenSSL library. 
You can either do not enable the modules, or install the OpenSSL library 
into the system, or build the OpenSSL library statically from the source 
with nginx by using –with-openssl= option.

解决方法: 


执行命令yum -y install openssl openssl-devel 成功之后再在nginx 源代码目录下运行 
./configure

启动nginx之后就可以开始推流了:

/usr/local/nginx/sbin/nginx  -c /usr/local/nginx/conf/live_rtmp.conf 
推流地址: rtmp://192.168.23.130:1935/mylive/test
播放地址: rtmp://服务器ip/mylive/test
hls地址: http://192.168.23.130:8080/hls/test.m3u8 
状态查看地址:http://192.168.23.130:8080/stat

猜你喜欢

转载自blog.csdn.net/qq_39526250/article/details/81390462
今日推荐