nginx rtmp-moduleの使い方 コンパイルインストールから詳しく説明しています。
映像配信を開始する時に、パスワード認証させたい
エンコーダからサーバに向けてなんでもOKではなくユーザ名とパスワード認証を行い、文字列が正しければエンコードを受け付ける
記事の元
https://helping-squad.com/nginx-rtmp-secure-your-nginx-server/
PHPスクリプトを噛ませておいて、PHPで認証が通ったもののみストリーム受け付ける
NginxでPHPを有効にする方法はこちら
https://www.techlive.tokyo/archives/1331
○Nginxのコンフィグに、rtmpストリーミング受付認証用のphpを通るように設定
/etc/nginx/nginx.conf
rtmp {
server {
listen 1935;
application live {
callow publish all;
deny publish all;
live on;
hls on;
hls_path /usr/local/nginx/html/live/hls;
on_publish http://localhost/auth.php;
notify_method get;
hls_type live;
}
}
}
※注意
Nginxのデフォルト通知方法はPostメソッドで成り立っているから、引数渡しなどができない。認証系を利用したければ必ず
notify_method get;
を入れる事
○auth.phpの中身
<?php
// www.server.com/auth.php?user=felix&pass=felixpassword
//check if querystrings exist or not
if(empty($_GET['user']) || empty($_GET['pass']))
{
//no querystrings or wrong syntax
echo "wrong query input";
header('HTTP/1.0 404 Not Found');
exit(1);
}
else
{
//querystring exist
$username = $_GET['user'];
$password = $_GET['pass'];
}
$savedpassword = felixpassword ;
$saveduser = felix ;
//check pass and user string
if (strcmp($password,$savedpassword)==0 && strcmp($username,$saveduser)==0 )
{
echo "Password and Username OK! ";
}
else
{
echo "password or username wrong! ";
header('HTTP/1.0 404 Not Found'); //kein stream
}
?>
○ストリーミング方法
rtmp://サーバIP/live/streamkey?user= felix&pass= felixpassword
OBSでの設定はこんな感じになります
サーバIP 192.168.200.50
配信ポイント live
ストリーム名 stream_name
ユーザ名 LiveEvent
パスワード PassWord
映像配信サーバを構築したい方はこちら