

借助 Nginx 搭建带简单认证的直播推流服务器,实现多平台同步直播
source link: https://blog.nanpuyue.com/2018/047.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

使用 nginx-rtmp-module 接收 rtmp 流,然后同时推送到多个直播平台,同时使用 lua-nginx-module 来做简单的身份验证。
安装必须的 nginx 模块
debian 9 用户可以直接使用 apt 安装,需启用 stretch-backports 源:
sudo apt install libnginx-mod-rtmp libnginx-mod-http-lua -t stretch-backports
nginx 配置
Gist: nginx.conf
# file: nginx.conf
# date: 2018-10-13
# license: GPLv3 https://www.gnu.org/licenses/gpl-3.0.txt
# author: nanpuyue <[email protected]> https://blog.nanpuyue.com
user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;
events {
worker_connections 768;
}
rtmp {
server{
listen 1935;
chunk_size 10240;
application live {
live on;
record off;
on_publish http://127.0.0.1:2080/auth;
push rtmp://live.twitch.tv/app/xxxxxxxxxx;
push rtmp://a.rtmp.youtube.com/xxxxxxxxxx;
}
}
}
http {
server {
listen 127.0.0.1:2080;
location /auth {
rewrite_by_lua '
ngx.req.read_body()
local name = ngx.req.get_post_args().name
if (name == "xxxxxxxxxx") then
ngx.status = 200
ngx.say("OK")
ngx.exit(200)
else
ngx.status = 403
ngx.say("Forbidden")
ngx.exit(403)
end
';
}
}
}
注意上面有三个 xxxxxxxxxx
是需要自己替换的,push 后面的是推流地址,替换成自己的,也可以自己再添加其他平台的;最后一个 xxxxxxxxxx
是我们想 nginx 推流时要使用的“流名称”,自己生成一个就好,推荐使用 uuidgen
生成一个 UUID。
检查身份验证
启动 nginx 服务后,在服务器上执行下面的命令:
curl -0 http://127.0.0.1:2080/auth -d "name=xxxxxxxxxx"
xxxxxxxxxx
替换成前面生成的 UUID,应该输出 OK,再把 xxxxxxxxxx
换成一个错误的,应该输出 Forbidden。
如果身份验证没有问题,我们就可以使用 obs 来推流了。
在 obs 设置中选择“自定义流媒体服务器”,URL 填入 rtmp://xx.xx.xx.xx/live
(xx.xx.xx.xx
是推流服务器的 ip 或域名), 流名称填入我们前面生成的 UUID。
设置好后单击 obs 上的“开始推流”,不出意外的话就可以同时向我们设置的平台推流了。
Recommend
-
9
SRS 流媒体服务器运行流程(推流端使用OBS,拉流端使用VLC) ...
-
13
微信视频号无人直播推流教程分享
-
11
今天在学习FFmpeg推流部分内容的时候,了解到了RTMP、HLS等直播推流的知识,初步了解了使用FFmpeg进行推流的命令使用方法。但是还是觉得缺点什么,纸上得来终觉浅。所以想自己动手搭建一个流媒体服务器,然后将本地的视频推流到该服务器,再使用VLC这类软件将该...
-
7
本文由微信开发团队工程师“virwu”分享。近期,微信小游戏支持了视频号一键开播,将微信升级到最新版本,打开腾讯系小游戏(如跳一跳、欢乐斗地主等),在右上角菜单就可以看到发起直播的按钮一键成为游戏主播了(如下图所示)。然而微信小游戏出...
-
12
nginx 流媒体服务器,nginx tcp http负载均衡,nginx 流转发,nginx 推流,nginx rtmp 用到了 https://github.com/winshining/nginx-http-flv-module user www-data; worker_processes auto; pid /run/nginx.pid; #worker_cpu_affinity auto...
-
10
nginx + nginx-rtmp-module + springboot 搭建直播流服务器实现推流、拉流实时直播功能 最近公司在做养老相关的业务,现在需要子女从小程序端对家里的老人...
-
14
一、基于RTMP协议的推流直播 首先需要手动搭建RTMP流服务器,搭建过程可以借鉴我的另外一篇文章 传送门 的第六章节。 打开OBS软件,新建 场景...
-
8
2022视频号直播推流攻略,建议收藏! 发布者: 91运营 ...
-
9
FFmpeg循环推流脚本|7×24小时陪伴型直播 | VPS小白 VPS小白 >
-
15
7×24无人值守直播推流软件开发实战,一文为你揭开视频推流的底层原理(附源码) ...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK