559 字
3 分钟
手把手教你:Nginx RTMP 直播安装配置,实现流畅直播!

RTMP直播需要Nginx-Rtmp模块,需要先卸载宝塔所安装的Nginx(或你目前已经安装了的Nginx,记得先备份好重要文件。),然后找到/www/server/panel/install/nginx.sh,Ctrl+F找

./configure

在后面加上

--add-module=/www/server/nginx_plus/nginx-rtmp-module

然后在ssh里执行

git clone https://github.com/arut/nginx-rtmp-module /www/server/nginx_plus/nginx-rtmp-module/

如你需要1.22则输入install 1.22,Tengine一样,非root用户需要sudo

sudo sh /www/server/panel/install/nginx.sh install 1.22

等待安装完成即可,时间取决于机器性能和网络因素等,安装完毕会显示 Staring nginx… done

安装完成后在终端 执行命令 nginx -V 查看是否安装成功

第二种方法
录面板——软件商店——运行环境——Nginx——安装
选择版本——编译安装——自定义模块
自定义编译模块参数
模块名称:

nginx_rtmp_module

模块描述:

nginx_rtmp_module

模块参数:

--add-module=/www/server/nginx/src/nginx-rtmp-module

前置脚本:

#安装依赖库
yum install libmaxminddb-devel -y
#下载第三方扩展源码
git clone https://github.com/arut/nginx-rtmp-module.git

点击“提交”。第四步,返回前面一个页面
勾选
点击“提交”进行编译并安装。

将RTMP相关的配置添加到NGINX的主配置文件中

rtmp {
server {
listen 1935;
chunk_size 4096;
application live {
live on;
record off;
hls on;
hls_path /www/wwwroot/www.123.com/live;
hls_fragment 5s;
}
}
}

/tmp/hls; 这里可以填写你网站的目录

HTTP配置
将HTTP相关的配置添加到BT面板管理的站点配置文件中

server {
listen 80;
server_name your_domain_or_ip; # 请用实际域名或IP替换
location / {
root html;
index index.html index.htm;
}
location /hls {
types {
application/vnd.apple.mpegurl m3u8;
video/mp2t ts;
}
root /www/wwwroot/www.123.com/live;
add_header Cache-Control no-cache;
}
}

接着可以安装
https://docs.kplayer.net/v0.5.8/

配置文件参考

{
"version": "2.0.0",
"resource": {
"lists": [
"/root/live/video/test01.mp4"
]
},
"output": {
"lists": [
{
"path": "rtmp://ip/live/test"
}
]
},
"play": {
"play_model": "loop",
"encode_model": "rtmp",
"encode": {
"video_width": 1280,
"video_height": 720,
"video_fps": 30,
"audio_channel_layout": 3,
"audio_sample_rate": 48000,
"bit_rate": 0,
"avg_quality": 0
},
"rpc": {
"on": true,
"http_port": 4156,
"grpc_port": 4157,
"address": "127.0.0.1"
}
},
"plugin": {
"lists": [
{
"path": "show-image",
"unique": "my_plugin",
"params": {
"filename": "/root/live/img/logo.png",
"x": "50",
"y": "70"
}
}
]
}
}

自用的配置

{
"version": "2.0.0",
"resource": {
"lists": [
"/root/live/video/"
],
"extensions": [ "mp4", "flv" ]
},
"output": {
"lists": [
{
"path": "rtmp://ip/live/test"
}
]
},
"play": {
"play_model": "loop",
"encode_model": "rtmp",
"encode": {
"video_width": 1280,
"video_height": 720,
"video_fps": 30,
"audio_channel_layout": 3,
"audio_sample_rate": 48000,
"bit_rate": 0,
"avg_quality": 10
},
"rpc": {
"on": true,
"http_port": 4156,
"grpc_port": 4157,
"address": "127.0.0.1"
}
},
"plugin": {
"lists": [
{
"path": "show-image",
"unique": "my_plugin",
"params": {
"filename": "/root/live/img/logo.png",
"x": "50",
"y": "70"
}
}
]
}
}
手把手教你:Nginx RTMP 直播安装配置,实现流畅直播!
https://blog.wlens.top/posts/rtmp直播/
作者
Lao Wang
发布于
2024-07-22
许可协议
CC BY-NC-SA 4.0