配置nginx.conf
rtmp {
server {
listen 1935;
chunk_size 4096;
#notify_method get; // 鉴权传参方式
application mtv {
live on;
publish_notify on;// 开启鉴权
on_publish http://{域名或IP}/index/auth; # 推流鉴权地址/接口
on_play http://{域名或IP}/index/auth; # 拉流鉴权地址/接口
record off;
}
}
}
这里使用TP框架
<?php
namespace app\index\controller;
use think\Controller;
class Auth extends Controller
{
public function index()
{
$liveKeys = [
'd0dbe915091d400bd8ee7f27f0791303',
'd8bd79cc131920d5de426f914d17405a'
];
$tokens = [
'c87d09e12130d2dd4c577e61645d677e',
'05b83edbd0a60b6c083af998db483a3c'
];
$token = input('post.token', '');
$name = input('post.name', '');
if (empty($token) || empty($name)) {
header('HTTP/1.1 401 Unauthorized');
header('Status: 401 Unauthorized');
exit();
}
if (!in_array($name, $liveKeys)) {
header('HTTP/1.1 401 Unauthorized');
header('Status: 401 Unauthorized');
exit();
}
if (!in_array($token, $tokens)) {
header('HTTP/1.1 401 Unauthorized');
header('Status: 401 Unauthorized');
exit();
}
header("HTTP/1.1 200 OK");
header("Status: 200 OK");
exit();
}
}
OBS推流配置
服务器:rtmp://{IP}/mtv
串流密钥: d0dbe915091d400bd8ee7f27f0791303?token=c87d09e12130d2dd4c577e61645d677e
web拉流地址:rtmp://{IP}:1935/mtv/d0dbe915091d400bd8ee7f27f0791303?token=05b83edbd0a60b6c083af998db483a3c