首页 > 系统相关 >Linux下搭建Nginx+nginx-rtmp-module流媒体服务器

Linux下搭建Nginx+nginx-rtmp-module流媒体服务器

时间:2023-08-10 17:02:42浏览次数:39  
标签:Nginx -- module nginx rtmp 服务器 root

今天我们使用的是linux系统为Centos 64位服务器。

下载安装nginx

首先新建nginx目录存放nginx:

mkdir nginx

1

然后进入nginx目录分别下载nginx及nginx-rtmp-module:

进入nginx目录

cd nginx

下载nginx

wget http://nginx.org/download/nginx-1.17.9.tar.gz

下载nginx-rtmp-module

https://codeload.github.com/arut/nginx-rtmp-module/tar.gz/v1.2.1

解压

// 解压 nginx

tar xvf nginx-1.17.9.tar.gz

// 解压nginx-rtmp-module

tar xvf v1.2.1

编译nginx

// 进入nginx下载目录

cd nginx-1.17.9

#执行configure生成makefile文件 --add-module 指向rtmp模块目录

./configure --prefix=./bin --add-module=../nginx-rtmp-module-1.2.1

发现报错了:

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

这是因为没有安装pcre导致的,我们使用yum包管理器安装一下pcre:

yum -y install pcre-devel

1

安装成功之后再执行./configure --prefix=./bin --add-module=../nginx-rtmp-module-1.2.1试下,发现还是报错:

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

这是因为缺少了openssl,我们安装OpenSSL:

yum -y install openssl openssl-devel

安装成功之后再执行./configure --prefix=./bin --add-module=../nginx-rtmp-module-1.2.1试下,成功了。

接着运行make install安装即可。

配置nginx

首先进入安装好的配置目录:

cd bin/conf

然后执行vim nginx.conf修改nginx.conf文件为:

user root;

worker_processes 1;

error_log logs/error.log debug;

events {

worker_connections 1024;

}

rtmp {

server {

#注意端口占用

listen 1935;

application myapp {

live on;

#丢弃闲置5s的连接

drop_idle_publisher 5s;

}

}

}

http {

server {

#注意端口占用

listen 8081;

location /stat {

rtmp_stat all;

rtmp_stat_stylesheet stat.xsl;

}

location /stat.xsl {

#注意目录

root /root/nginx/nginx-rtmp-module-1.2.1/;

}

location /control {

rtmp_control all;

}

location /rtmp-publisher {

#注意目录

root /root/nginx/nginx-rtmp-module-1.2.1/test;

}

location / {

#注意目录

root /root/nginx/nginx-rtmp-module-1.2.1/test/www;

}

}

}

启动与停止

启动nginx服务器:

bin/sbin/nginx

1

启动服务器后在浏览器输入你服务器的ip:端口如果可以访问则说明配置成功了。

停止nginx服务器:

bin/sbin/nginx -s stop

1

使用ffmpeg测试推流与拉流

如果你还不知道如何安装ffmpeg命令行环境,建议你参考这篇文章《手把手教你搭建ffmpeg命令行运行环境》

执行推流命令:

ffmpeg -re -i 需要推流的视频文件 -vcodec libx264 -acodec aac -f flv rtmp://服务器ip:1935/myapp/videopushTest

1

推流成功后,我们使用ffplay命令测试能否播放:

ffplay rtmp://服务器ip:1935/myapp/videopushTest

1

如果能正常播放,说明我们的流媒体服务器就搭建成功啦。


标签:Nginx,--,module,nginx,rtmp,服务器,root
From: https://blog.51cto.com/u_16110906/7037582

相关文章

  • 8.利用Filebeat收集Nginx的Json格式访问日志和错误日志到Elasticsearch
    生产环境中经常需要获取Web访问用户的信息,比如:网站的PV,UV,状态码,用户来自哪个地区,访问时间等可以通过收集的Nginx的访问日志实现默认Nginx的每一次访问生成的访问日志是一行文本,ES没办法直接提取有效信息,不利于后续针对特定信息的分析可以将Nginx访问日志转换为JSON......
  • .configure error SSL modules require the OpenSSL library.
    CentOS6.5下安装Tengine执行配置命令./configure时提示以下错误:./configure:error:SSLmodulesrequiretheOpenSSLlibrary.Youcaneitherdonotenablethemodules,orinstalltheOpenSSLlibraryintothesystem,orbuildtheOpenSSLlibrarystaticallyfromt......
  • 一种基于Nginx的热点数据调度处理方法
    本文分享自天翼云开发者社区《一种基于Nginx的热点数据调度处理方法》,作者:康****彬一、应用场景  基于Nginx的热点数据调度处理,热点节点数据负载均衡处理,减少热点节点压力,提高处理和访问效率;每一个节点的nginx服务接收大量的访问,但是每个节点处理请求都有一个峰值,当请求数......
  • Nginx 大文件分片上传处理
    ​ 以ASP.NETCoreWebAPI 作后端 API ,用 Vue 构建前端页面,用 Axios 从前端访问后端 API,包括文件的上传和下载。 准备文件上传的API #region 文件上传  可以带参数        [HttpPost("upload")]        publicJsonResultuploadProject(I......
  • nginx动静分离及Rewrite实战
                  (1)location=/{}=为精确匹配/,主机名后面不能带任何字符串,比如访问/和/data,则/匹配,/data不匹配再比如location=/abc,则只匹配/abc,/abc/或/abcd不匹配。若location/abc,则即匹配/abc、/abcd/同时也匹......
  • 【Nginx用法】nginx location正则表达式写法,详解Nginx location 匹配规则(很详细哦)
    本文目录一、常用规则 二、实际使用建议三、Flag标志位四、If判断指令五、全局变量六、常用正则七、Rewrite规则八、Rewrite实例8.1实例一8.2实例二九、项目实例9.1项目一9.2项目实战作为一名Java开发人员,有些东西不经常使用,很容易忘记,好比nginx配置内容,以下内容是记录了公司......
  • nginx降低爬虫的效率
    环境nginx1.20理由不说了,就是通过Nginx一些策略来帮助防止爬虫或恶意访问配置User-Agent检测爬虫通常会使用特定的User-Agent来标识自己,Nginx可以通过检测User-Agent字符串并拒绝使用非法的User-Agent的请求。if($http_user_agent~*"badcrawler"){return403;//......
  • Nginx集群
    Nginx集群Nginx集群 Nginx简介Nginx("enginex")是一个高性能的HTTP和反向代理服务器,也是一个IMAP/POP3/SMTP代理服务器。Nginx是由IgorSysoev为俄罗斯访问量第二的Rambler.ru站点开发的,它已经在该站点运行超过两年半了。Igor将源代码以类BSD许可证的......
  • Nginx 转发请求的时候,丢失请求头
    请求连接:curl-H"Content-Type:application/json;charset=utf-8"-H"channel_id:21520160723000110027"-H"sequenceid:1122"http://127.0.0.1:1095/app/api/gqzr/swxxcx-XPOST-d'{"shxydm":"911500002115000009D&quo......
  • nginx部署windows
    location/{rootD:\\nginx-1.24.0\\html\\dist;try_files$uri$uri//index.html;indexindex.htmlindex.htm;} location/api/{proxy_set_headerHost$http_host;proxy_set_headerX-Real-IP$r......