宝塔面板搭建推流服务器
时间: 2025-03-07 14:01:08 浏览: 59
### 使用宝塔面板搭建 RTMP 推流服务器
#### 准备工作
为了顺利搭建 RTMP 推流服务器,需满足以下基础条件[^3]:
- Linux 服务器一台。
- 已安装并正常运行的宝塔面板。
#### 卸载默认 Nginx 版本
由于宝塔面板自带的 Nginx 不支持 RTMP 模块,因此需要先卸载现有的 Nginx 实例。这一步骤至关重要,以防止配置冲突影响后续操作[^1]:
```bash
yum remove nginx -y
```
#### 编译安装带 RTMP 支持的 Nginx
进入宝塔面板管理界面,在软件商店找到 Nginx 并点击“设置”,选择自定义编译选项,勾选 `ngx_rtmp_module` 后保存设置并重新编译安装 Nginx[^2]:

#### 配置 NGINX-RTMP 模块
编辑 `/www/server/nginx/conf/nginx.conf` 文件,添加如下配置片段用于启用 RTMP 功能和支持 HLS 协议[^4]:
```nginx
rtmp {
server {
listen 1935;
chunk_size 4096;
application live {
live on;
record off;
hls on;
hls_path /mnt/hls;
hls_fragment 1s;
}
}
}
```
同时确保 HTTP 块内存在指向上述 HLS 路径的服务端口监听:
```nginx
http {
...
server {
location /hls {
types {
application/vnd.apple.mpegurl m3u8;
video/mp2t ts;
}
root /mnt/;
add_header Cache-Control no-cache;
}
...
}
...
}
```
完成以上修改后重启 Nginx 生效更改。
#### 测试推流服务
使用 OBS Studio 或其他直播工具连接至服务器地址 `rtmp://your_server_ip/live/stream_key` 进行测试推送。当 OBS 底部显示绿色确认框时表示推流成功[^5]。
```python
import os
os.system('ffmpeg -re -i test.mp4 -c copy -f flv rtmp://localhost/live/test')
```
此命令可用于模拟本地文件作为输入源向 RTMP 服务器发送数据流。
阅读全文
相关推荐


















