Linux平台下使用nginx与nginx-rtmp-module搭建RTMP+HLS流媒体服务器
Linux平台下使用nginx与nginx-rtmp-module搭建RTMP+HLS流媒体服务器
- 下载nginx-rtmp-module
命令:wget https://github.com/arut/nginx-rtmp-module/archive/master.zip
提示:服务器没有安装git command not found
CentOS下使用命令:yum install git –y
yum install -y unzip zip
解压:unzip master.zip
安装之后返回 cd ~
- 编译安装Nginx
a.安装zlib库
命令:wget http://www.zlib.net/zlib-1.2.11.tar.gz
命令:tar xf zlib-1.12.11.tar.gz
cd zlib-1.2.11
./configure
make && make install
安装完返回 cd ~
b.安装openssl库
命令:wget https://www.openssl.org/source/openssl-1.0.2l.tar.gz
tar xf openssl-1.0.2l.tar.gz
cd openssl-1.0.2l
./config
make && make install
安装完返回 cd ~
c.安装pcre库
只要安装bzip2
yum -y install bzip2
**命令:wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.38.tar.bz2
安装pcre包的时候提示缺少c++编译器
安装命令:yum –y install gcc-c++
更改yum 配置
tar xf pcre-8.38.tar.bz2
cd pcre-8.38
./configure
make && make install
安装完返回 cd ~
d.编译安装Nginx
命令:wget http://nginx.org/download/nginx-1.13.4.tar.gz
tar xf nginx-1.13.4.tar.gz
cd nginx-1.13.4
./configure --prefix=/usr/local/nginx --add-module=../nginx-rtmp-module-master --with-http_ssl_module --with-pcre=../pcre-8.38 --with-openssl=../openssl-1.0.2l --with-zlib=../zlib-1.2.11
make && make install
返回 cd ~
- 执行完以上步骤,不出错误的话,Nginx编译出生成到/usr/local/nginx 目录
cd ~
cd /usr/local/nginx/
tree
如果tree没有安装的话,请安装tree
命令:yum install tree
查看安装是否成功命令:yum list installed tree
再执行 tree
- Nginx配置
输入命令:
vim /usr/local/nginx/conf/nginx.conf
按“insert”键
加入以下内容
hls_path 需要可读可写的权限
cd ~
chmod 777 /html/hls
出现以下错误:
nginx: [emerg] mkdir() “/html/hls” failed (2: No such file or directory)
解决办法:mkdir -p /html/hls
修改http中server模块
退出 :qw
回车
然后重启nginx
/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
关闭Linux防火墙
systemctl stop firewalld.service
关闭开机启动
systemctl disable firewalld.service
- 使用OBS推流
服务器的地址即是我的虚拟机ip 及hls
- 参考文档:
https://blog.csdn.net/liuchen1206/article/details/77771703
https://blog.csdn.net/l1028386804/article/details/80022437
https://blog.csdn.net/heng615975867/article/details/80519274
备注: 删除nginx
进入到这个nginx的目录
yum remove nginx
./nginx -c conf/nginx.conf
./nginx -s reload
192.168.31.133 nginx访问不了,OBS连接服务器失败
进入nginx可执行目录sbin下输入./nginx -s reload 即可
输入完要是提示nginx: [error] invalid PID number "" in "/usr/local/nginx/logs/nginx.pid"
解决:/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
Nginx 设置开机自启动
在rc.local增加启动代码
vi /etc/rc.local
增加一行 /usr/local/nginx/sbin/nginx
设置执行权限:
chmod 755 rc.local
chmod 755 /etc/rc.local
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
nginx -s reload
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· Vue3状态管理终极指南:Pinia保姆级教程