本ページは広告が含まれています。気になる広告をクリック頂けますと、サーバ運営費になります(^^
セキュアリンクを、ライブストリーミングでかける事は出来た。

Streaming with nginx-rtmp-module Secure links
さて、セキュアリンクの基本が分かったところで次のステップへ進めます。Nginxとセキュアリンクの基本設定はこちらでは次は本番です。rtmp:// にセキュアリンクを使って直リンクを防ぎますngix.confに、以下を追記し、8080でも受け...
これを、オンデマンド配信で利用するためにはどうしたらよいのか。
今回はDebianで実現したので、php-fpmの配置がちょっと違うので注意。
https://www.techlive.tokyo/archives/1331
vod2 の位置にbbb.mp4を配置。セキュアリンクする前にちゃんとオンデマンドできているのか確認する事。

nginx rtmp-module にてオンデマンド配信を実現
すでにあるflvや、mp4 をrtmpで映像配信する。Video on demandmp4または、flvファイルを準備し、/usr/local/nginx/mp4s;/usr/local/nginx/flvs;に配置しておく今回のテストでは...
再生はvideojs を利用し、さらにphpでセキュアリンク用のハッシュを計算させて、それをrtmp url に付加させることで実現している。
/etc/nginx/nginx.conf
worker_processes 1;
events {
worker_connections 1024;
}
rtmp {
server {
listen 1935;
notify_method get;
chunk_size 4000;
# video on demand for flv files
application vod {
play /usr/local/nginx/flvs;
on_play http://localhost:8080/on_play;
}
# video on demand for mp4 files
application vod2 {
play /usr/local/nginx/mp4s;
on_play http://localhost:8080/on_play;
}
}
}
# HTTP can be used for accessing RTMP stats
http {
access_log /usr/local/nginx/logs/access-streaming.log;
error_log /usr/local/nginx/logs/error-streaming.log;
server {
# in case we have another web server on port 80
listen 80;
location / {
root html;
index index.html index.htm;
}
location ~ \.php$ {
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
listen 8080;
server_name localhost;
location /on_play {
# set connection secure link
secure_link $arg_st,$arg_e;
secure_link_md5 mysecretkey$arg_app/$arg_name$arg_e;
# bad hash
if ($secure_link = "") {
return 501;
}
# link expired
if ($secure_link = "0") {
return 502;
}
return 200;
}
}
}
vi /usr/local/nginx/html/vod.php
<html>
<head>
<link href="http://vjs.zencdn.net/5.11.6/video-js.css" rel="stylesheet">
<script src="http://vjs.zencdn.net/5.11.6/video.js"></script>
</head>
<body>
<video id="rtmp_test" class="video-js vjs-default-skin" autoplay="autoplay" controls="controls" width="800" height="450" data-setup="{}">
<?php
// 秘密鍵 になります。なんでもOKですので、ここでは日本語(UTF-8)で設定してみます。
$secret = 'mysecretkey';
// セキュアなリンク からでないとアクセスできないURIを設定します。
$path = 'vod2/bbb.mp4';
// 公開鍵として、有効期限を time() + 秒 で設定します。
// -- この有効期限の設定の仕方は、Nginxではこの方法でしか認識できません。
$timestamp = time() + 3600; // 60(秒) x 60(分) = 3600(秒) = 1(時)
// "秘密鍵 + パス + 公開鍵" を Nginxで扱うことができる md5 で暗号化します。
$hash = base64_encode(md5($secret . $path . $timestamp, true));
// +,/,= は、URLパラメータとして扱えないので、置換します。
$hash = strtr($hash, '+/', '-_');
$hash = str_replace('=', '', $hash);
// セキュアなリンクを出力します。
$url = "{$path}?e={$timestamp}&st={$hash}";
echo '<source src="rtmp://サーバIPアドレス/'.$url.'" type="rtmp/mp4" />'
?>
</video>
</body>
</html>

