本ページは広告が含まれています。気になる広告をクリック頂けますと、サーバ運営費になります(^^
さて、セキュアリンクの基本が分かったところで次のステップへ進めます。
Nginxとセキュアリンクの基本設定はこちら
https://www.techlive.tokyo/archives/1347
では次は本番です。rtmp:// にセキュアリンクを使って直リンクを防ぎます
Secure links in nginx-rtmp
Many people ask me for secure link support in nginx-rtmp similar to nginx http secure links . The truth is no special su...
ngix.confに、以下を追記し、8080でも受け付けておく。通常の80へのアクセスは既存のままでよくて追記する。あ、もし8080だけ動かすなら上記リンク先の通り、http{ディレクティブが必要。
/etc/nginx/nginx.conf
server {
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;
}
}
rtmp {
server {
listen 1935;
#notify_methodは必ず必要なので入れる事
notify_method get;
# protected application
application myapp {
live on;
on_play http://localhost:8080/on_play;
}
}
}
エンコード開始してアクセスしてみる
rtmp://サーバIP/live/test
今までアクセスできていた方法でアクセスしてみるとアクセスできなくなってる(正常)
以下、そのログでon_playに飛ばされた後、disconnect されているのが分かる
2016/10/08 11:13:29 [info] 14275#0: *17 client connected 'クライアントIP' 2016/10/08 11:13:29 [info] 14275#0: *17 connect: app='live' args='' flashver='WIN 23,0,0,162' swf_url='http://vjs.zencdn.net/swf/5.1.0/video-js.swf' tc_url='rtmp://video.hanako.or.jp/live/' page_url='http://video.hanako.or.jp/rtmp.html' acodecs=3575 vcodecs=252 object_encoding=3, client: クライアントIP, server: 0.0.0.0:1935 2016/10/08 11:13:29 [info] 14275#0: *17 createStream, client: クライアントIP, server: 0.0.0.0:1935 2016/10/08 11:13:29 [info] 14275#0: *17 play: name='test' args='' start=0 duration=0 reset=0 silent=0, client: クライアントIP, server: 0.0.0.0:1935 2016/10/08 11:13:29 [info] 14275#0: *17 notify: play 'localhost:8080/on_play', client: クライアントIP, server: 0.0.0.0:1935 2016/10/08 11:13:29 [info] 14275#0: *17 disconnect, client: クライアントIP, server: 0.0.0.0:1935 2016/10/08 11:13:29 [info] 14275#0: *17 deleteStream, cl
で、セキュアリンク用の文字列を作成する
#date +%s #1475892965 #echo $((1475892965+3600)) #1475896565 #echo -n "mysecretkeylive/test1475896565" | openssl dgst -md5 -binary | openssl enc -base64 | tr #'+/' '-_' | tr -d '=' #LPpV0HfjOrdXnwStNcHYCA
※注意 mysecretkeyは任意に変える liveは配信ポイント test はsteamkeyになってる
でアクセスしてみる
rtmp://サーバIP/live/test?e=1475896565&st=LPpV0HfjOrdXnwStNcHYCA
再生できた!!
2016/10/08 11:28:01 [info] 14275#0: *31 client connected 'クライアントIP' 2016/10/08 11:28:01 [info] 14275#0: *31 connect: app='live' args='' flashver='WIN 23,0,0,162' swf_url='http://vjs.zencdn.net/swf/5.1.0/video-js.swf' tc_url='rtmp://video.hanako.or.jp/live/' page_url='http://video.hanako.or.jp/rtmp.html' acodecs=3575 vcodecs=252 object_encoding=3, client: クライアントIP, server: 0.0.0.0:1935 2016/10/08 11:28:01 [info] 14275#0: *31 createStream, client: クライアントIP, server: 0.0.0.0:1935 2016/10/08 11:28:01 [info] 14275#0: *31 play: name='test' args='e=1475896565&st=LPpV0HfjOrdXnwStNcHYCA' start=0 duration=0 reset=0 silent=0, client: クライアントIP, server: 0.0.0.0:1935 2016/10/08 11:28:01 [info] 14275#0: *31 notify: play 'localhost:8080/on_play', client: クライアントIP, server: 0.0.0.0:1935
※上記再生はvideojsを利用して再生してます。
https://www.techlive.tokyo/archives/1255
こんな感じ
<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="{}">
<source src="rtmp://video.hanako.or.jp/live/test?e=1475896565&st=LPpV0HfjOrdXnwStNcHYCA" type="rtmp/mp4" />
</video>
</body>
</html>