在 nginx 中配置 rtmp 的步驟有:安裝 rtmp 模塊編輯 nginx 配置文件,添加 rtmp 配置創建用于推送和拉取流的 rtmp 流源重啟 nginx使用 vlc 播放器驗證配置
如何在 Nginx 中配置 RTMP
為了在 Nginx 中配置 RTMP,請按照以下步驟操作:
1. 安裝 RTMP 模塊
apt-get install <a style="color:#f60; text-decoration:underline;" href="https://www.php.cn/zt/16000.html" target="_blank">nginx</a>-module-rtmp
登錄后復制
2. 配置 Nginx
在 Nginx 配置文件 /etc/nginx/nginx.conf 中,添加以下內容:
rtmp {
server {
listen 1935;
chunk_size 4096;
application live {
push "push.stream";
pull "live.stream";
live on;
}
}
}
登錄后復制
3. 創建 RTMP 流源
創建兩個流源,一個用于推送流,一個用于拉取流:
# 推送流源 ffmpeg -re -i input.mp4 -vcodec libx264 -acodec aac -f flv rtmp://localhost:1935/live/push.stream # 拉取流源 ffmpeg -i rtmp://localhost:1935/live/live.stream output.mp4
登錄后復制
4. 重啟 Nginx
systemctl restart nginx
登錄后復制
5. 驗證配置
您可以使用 VLC 媒體播放器連接到 RTMP 流源以驗證配置:
推送流:rtmp://localhost:1935/live/push.stream
拉取流:rtmp://localhost:1935/live/live.stream






