[b]前言[/b]
相信大家都知道nginx是非常优秀的开源服务器,用它来做hls或者rtmp流媒体服务器是非常不错的选择,所以小编在网上整理了安装流程,现在分享给大家并且作备忘。有需要的朋友们可以参考学习,下面来一起看看吧。
[b]一、安装Homebrow[/b]
已经安装了brow的可以直接跳过这一步。
执行命令
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
如果已经安装过,而想要卸载:
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall)"
[b]二、安装nginx[/b]
先glone nginx项目到本地:
执行安装:
brew install nginx-full --with-rtmp-module
安装过程比较缓慢,耐心等待
通过操作以上步骤nginx和rtmp模块就安装好了,下面开始来配置nginx的rtmp模块
首先来看看我们的nginx安装在哪里了
执行上面的命令后我们可以看到信息
[img]http://files.jb51.net/file_images/article/201609/201692990714864.png?20168299747[/img]
nginx安装所在位置
/usr/local/Cellar/nginx-full/1.10.1/bin/nginx
nginx配置文件所在位置
/usr/local/etc/nginx/nginx.conf
[b]三、运行nginx[/b]
执行命令 ,测试下是否能成功启动nginx服务
命令行如下图所示
[img]http://files.jb51.net/file_images/article/201609/201692990934965.png?20168299942[/img]
在浏览器地址栏输入:http://localhost:8080 (直接点击)
如果出现
[img]http://files.jb51.net/file_images/article/201609/201692991032552.png?201682991041[/img]
Welcome to nginx!.03
代表nginx安装成功了
如果终端上提示
nginx: [emerg] bind() to 0.0.0.0:8080 failed (48: Address already in use)
则表示8080
端口被占用了, 查看端口PID
kill掉占用8080端口的PID
kill 9603(这里替换成占用8080端口的PID)
然后重新执行nginx
nginx常用方法:重新加载配置文件
重新加载日志:
// 停止 nginx
// 有序退出 nginx
[b]四、配置rtmp[/b]
现在我们来修改nginx.conf这个配置文件,配置rtmp
复制nginx配置文件所在位置
/usr/local/etc/nginx/nginx.conf
打开Finder Shift + command + G前往,用记事本工具打开nginx.conf
在http节点后面加上rtmp配置:
rtmp {
server {
listen 1935;
#直播流配置
application rtmplive {
live on;
#为 rtmp 引擎设置最大连接数。默认为 off
max_connections 1024;
}
application hls{
live on;
hls on;
hls_path /usr/local/var/www/hls;
hls_fragment 1s;
}
}
}
[b]五、安装ffmepg工具[/b]
安装这个需要等一段时间等待吧 然后准备一个视频文件作为来推流,然后我们在安装一个支持rtmp协议的视频播放器,Mac下可以用VLC
[img]http://files.jb51.net/file_images/article/201609/201692991429689.png?201682991438[/img]
VLC.04
显示下图表示ffmpeg安装完毕
[img]http://files.jb51.net/file_images/article/201609/201692991457534.png?20168299155[/img]
ffmpeg安装完毕0.5
[b]六、ffmepg 安装完成后可以开始推流了[/b]
ffmpeg -re -i 你的视频文件的绝对路径(如/Users/lideshan/Downloads/Demo.mp4) -vcodec copy -f flv rtmp://localhost:1935/zbcs/room
// 如:ffmpeg -re -i /Users/jiangys/Documents/Document/demo.mp4 -vcodec copy -f flv rtmp://localhost:1935/zbcs/room
这里zbcs是上面的配置文件中,配置的应用的路径名称;后面的room可以随便写。
推流界面:
[img]http://files.jb51.net/file_images/article/201609/201692991715842.jpg?201682991849[/img]
[b]七、验证视频[/b]
然后电脑上打开vlc这个播放器软件 点击[code]File---->Open Network [/code]在弹出来的框中选择Network然后输入URL:
rtmp://localhost:1935/zbcs/room
[img]http://files.jb51.net/file_images/article/201609/201692992025133.jpg?201682992034[/img]
双击播放
[img]http://files.jb51.net/file_images/article/201609/201692992122100.png?201682992136[/img]
播放界面
[img]http://files.jb51.net/file_images/article/201609/201692992201159.png?20168299228[/img]
[b]报错处理[/b]
1.ffmepg命令推流的时候,提示连接失败。 [code][tcp @ 0x7ff162504b60] Connection to tcp://localhost:1935 failed (Connection refused), trying next address[/code]
出现这个错,是因为配置了nginx.conf后,需要重启nginx。输入命令重启后就没有问题了
[img]http://files.jb51.net/file_images/article/201609/201692992326199.jpg?20168299241[/img]
2.安装完nginx后,在浏览器地址栏输入:[url=http://localhost:8080]http://localhost:8080[/url] 显示打不开网页
解决方式:由于安装后nginx服务器,有时需要等上几分钟才生效。如果还不生效,测试下是否能成功启动nginx服务,命令
具体请参考“步骤安装”第三点。
[b]总结[/b]
好了,到这就基本安装结束了,大家安装步骤一步步来都可以安装成功的,以上就是这篇文章的全部内容,希望能对大家的学习或者工作带来一定的帮助,如果有疑问大家可以留言交流。