Ubuntu nginx-rtmp环境

来源:互联网 发布:安信股票交易软件 编辑:程序博客网 时间:2024/05/22 06:22

首先需要在ubuntu下安装nginx服务器

sudo apt-get install nginx

然后尝试访问本地http服务器

http://127.0.0.1

如果安装成功会看到nginx的欢迎界面
这里写图片描述

然后需要将nginx-rtmp模块添加到nginx服务器中,nginx-rtmp是一个第三方的nginx扩展库,nginx和apache不同,不能直接加载.so文件,所以我们需要下载nginx与nginx-rtmp源码,重新编译然后替换源程序。
首先我们需要查看当前安装的版本,使用命令

nginx -V

这里写图片描述
这里可以看到nginx的版本以及相应的编译参数
通过wget命令下载相应的源码

wget http://nginx.org/download/nginx-1.10.0.tar.gz #下载nginx源码wget https://github.com/arut/nginx-rtmp-module/archive/master.zip #下载nginx-rtmp

获得源码之后将两个包解压缩,然后切换到nginx源码目录,然后配置configure

./configure +(nginx -V命令configure arguments之后的配置信息 )+ --add-module=../nginx-rtmp-module-master

可能会出现一些错误,比如

/configure: error: the HTTP XSLT module requires the libxml2/libxslt libraries.

这个需要安装libxslt-dev

sudo apt-get install libxslt-dev

接着会出现

./configure: error: the HTTP image filter module requires the GD library.

这个是因为缺少GD library

sudo apt-get install libgd2-dev

然后会出现

./configure: error: the GeoIP module requires the GeoIP library.

需要安装GeoIP library

sudo apt-get install libgeoip-dev

然后配置会通过,使用make命令开始编译,等待编译完成,这时候不能够直接使用make install命令,这样的话会把整个程序都覆盖掉,我们只能进行主程序的替换,首先将原有的nginx服务暂停

sudo service nginx stop

然后将objs/nginx替换掉/usr/sbin/nginx

sudo cp objs/nginx /usr/sbin/nginx

然后重新启动服务

sudo service nginx start

可以正常启动的话就说明编译成功了,然后需要配置rtmp服务,

sudo vim /etc/nginx/nginx.conf

在最后一行添加

server {            listen 2017;            chunk_size 4096;            application live {                    live on;                    hls on;        }    }

重新启动服务

sudo service nginx restart

这样就搭建好了nginx-rtmp服务,可以找一个视频流测试一下,使用ffmpeg推流

ffmpeg -re -i mi.mp4 -c copy -f flv rtmp://localhost:2017/live/file

可以使用vlc进行播放测试
这里写图片描述

0 0