美文网首页
Nginx安装rtmp模块

Nginx安装rtmp模块

作者: 黑铁大魔王 | 来源:发表于2018-04-24 11:30 被阅读0次

1. 编译安装nginx

a. 如果以前通过apt-get安装了nginx,需要卸载(sudo apt remove nginx)

b. 去官网下载nginx http://nginx.org/en/download.html(我用的是1.12) 

c. 下载nginx-rtmp-module

    官方github地址:https://github.com/arut/nginx-rtmp-module,

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

d. 解压下载的nginx,进入nginx目录,写一个配置脚本config_nginx_1.12.sh内容如下:

./configure --prefix=/usr/local/nginx \

--add-module=../nginx-rtmp-module \

--with-http_flv_module \

--with-http_mp4_module \

执行:

chmod +x config_nginx_1.12.sh

./config_nginx_1.12.sh

可能会报出如下错误:

./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= option.  

原因:HTTP rewrite模块需要PCRE 库,要么你加个不要这个模块的选项重新配置nginx,要么就安装PCRE。当然必须选择安装PCRE。

sudo apt install libpcre3 libpcre3-dev

系统报告libpcre3早就装好了,其实只需要装开发库libpcre3-dev。

重新配置,这次报告是需要OpenSSL,继续装:

sudo apt install openssl libssl-dev

系统报告openssl早就装好了,已经是最新版本了,想来还是跟PCRE一样,只需要装个开发库。

继续./config_nginx_1.12.sh

然后 make

sudo make install

2. 配置nginx

sudo vim /usr/local/nginx/conf/nginx.conf

在文件最后增加如下内容

rtmp {

    server {       

        listen 1935;  #监听的端口

        chunk_size 4000;

        application hls {  #rtmp推流请求路径: rtmp://ipaddress:1935/hls 

            live on;

            hls on;

            hls_path /usr/local/nginx/html/hls;

            hls_fragment 5s;

        }

     }

 }

这里的视频流目录:hls_path设置为 /usr/local/nginx/html/hls,这个目录的权限设置为775。

3. 启动nginx

启动nginx就可以了。。。

相关文章

网友评论

      本文标题:Nginx安装rtmp模块

      本文链接:https://www.haomeiwen.com/subject/lufgkftx.html