Linux安装nginx
一般我们都需要先装pcre, zlib,前者为了重写rewrite,后者为了gzip压缩。
1.选定源码目录
<code style="margin-left:0">cd /usr/local/src</code>
2.安装PCRE库
下载
<code style="margin-left:0">wget https://netix.dl.sourceforge.net/project/pcre/pcre/8.40/pcre-8.40.tar.gz</code>
解压安装包
<code style="margin-left:0">tar -zxvf pcre-8.40.tar.gz</code>
进入安装目录
<code style="margin-left:0">cd pcre-8.40</code>
编译安装
<code style="margin-left:0">./configure make && make install</code>
查看pcre版本
<code style="margin-left:0">pcre-config --version</code>
3.安装zlib库
<code style="margin-left:0">wget http://www.zlib.net/zlib-1.2.11.tar.gz tar -zxvf zlib-1.2.11.tar.gz cd zlib-1.2.11 ./configure make && make install</code>
4.安装Nginx
<code style="margin-left:0">cd /usr/local/ wget http://nginx.org/download/nginx-1.15.3.tar.gz tar -zxvf nginx-1.15.3.tar.gz rm nginx-1.15.3.tar.gz mv nginx-1.15.3 nginx cd nginx/ ./configure --prefix=/usr/local/nginx make & make install</code>
遇到错误,先不管继续以下步骤
添加Nginx环境变量,可以在命令行直接输入Nginx命令
<code style="margin-left:0">vim /etc/profile</code>
在最后添加Nginx的路径
<code style="margin-left:0">export NGINX_HOME=/usr/local/nginx export PATH=$PATH:$NGINX_HOME/sbin</code>
重新编译环境变量
<code style="margin-left:0">source /etc/profile</code>
启动nginx
<code style="margin-left:0">mkdir /usr/local/nginx/logs cd sbin ./nginx</code>
浏览器输入IP,就会有nginx欢迎界面
重启nginx命令为
<code style="margin-left:0">nginx -s reload</code>
关闭nginx服务:
<code style="margin-left:0">killall -9 nginx</code>
遇到的问题
<code style="margin-left:0">nginx:[emerg] listen()to 0.0.0.0:80, backlog 511 failed (98: Address already in use) . . . nginx:[emerg] sill could not blind()</code>
提示端口已被占用
查看端口占用情况
<code style="margin-left:0">sudo netstat -ntpl</code>
我的是
<code style="margin-left:0">tcp6 0 0 :::80 :::* LISTEN 1128/apache2</code>
然后杀死1128的任务
<code style="margin-left:0">sudo kill 1128</code>
重启Nginx便可
也又可能是防火墙没有打开80端口
打开80端口
<code style="margin-left:0">iptables -I INPUT -p tcp --dport 80 -j ACCEPT</code>
5.安装Nginx的rtmp拓展
<code style="margin-left:0">cd /usr/local/nginx</code>
还缺少openssl环境,需要手动安装
<code style="margin-left:0">sudo apt-get install libssl-dev</code>
如果报错
<code style="margin-left:0">ERR:1 http://... 404 Not Found</code>
更新一下
<code style="margin-left:0">apt-get update</code>
再进行安装
<code style="margin-left:0">sudo apt-get install libssl-dev git clone https://github.com/arut/nginx-rtmp-module.git ./configure --add-module=/usr/local/nginx/nginx-rtmp-module make & make install</code>
6.配置Nginx的rtmp服务站点
<code style="margin-left:0">vim /usr/local/nginx/conf/nginx.conf</code>
在文件底部添加下面内容
<code style="margin-left:0">rtmp{ server{ #监听的端口 listen 1935; chunk_size 4000; application tv_file{ #开启实时 live on; #开启hls hls on; #rtmp推流请求路径,文件存放路径 hls_path /usr/local/nginx/html/tv_file; #每个TS文件包含5秒的视频内容 hls_fragment 5s; } } }</code>
在文件中部,修改http的server模块
<code style="margin-left:0">location/{ root /usr/local/nginx/html; index index.html index.htm }</code>
打开1935端口,建议阿里云
启动nginx
<code style="margin-left:0">cd /usr/local/nginx/sbin ./nginx</code>
测试:
windows 终端
<code style="margin-left:0">telnet 服务器地址 1935</code>
遇到的问题:
telnet不可用,
控制面板->程序和功能->启用和关闭Windows功能->勾选Telnet Client
7.推流测试
下载 OBS Studio
下载地址:https://pc.qq.com/detail/4/detail_23604.html
安装完成后,打开软件
在 来源 模块,点击+,媒体源,新建一个,
在本地文件添加一个视频文件上去,
勾选:循环、当源变为活跃状态时重新启动播放、在可用时使用硬件解码
在右下角 控件 模块,点击设置,点击推流
服务:自定义
服务器:rtmp://服务器地址:1935/tv_file
串流密钥:test(这处随便,也就是保存到服务器端的文件名)
开始推流:
然后在服务器段就可以看到 .ts .m3u8文件
<code style="margin-left:0">cd /usr/local/nginx/html/tv_file ls test-0.ts test-1.ts test-2.ts test.m3u8 </code>
8.拉流测试
下载安装 VLC
下载地址 https://www.videolan.org/
点击媒体->打开网络串流
选择网络,在URL里输入 流媒体服务器IP和串流密钥
<code style="margin-left:0">rtmp://服务器地址:1935/tv_file/test</code>
点击播放
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/179933.html原文链接:https://javaforall.cn
未经允许不得转载:木盒主机 » 3、搭建rtmp视频推流服务器