本ページは広告が含まれています。気になる広告をクリック頂けますと、サーバ運営費になります(^^
惨々探し回ったけど、やっぱりお金を払わないとSecure Linkを使ったHLS配信は無料では出来なさそう。何か、有料のモジュールなどを購入しないといけない。
そこで、無料でできる範囲で試行錯誤して何とかreferer判断する事で直リンクを避ける事だけはできた。セキュリティ的にまだ問題があるかもしれないけど。一応忘れないように。
単純にm3u8,tsファイルができるフォルダにbasic認証をかけると、tsファイルが無数にできる関係で、その都度パスワード認証が出てきて、とても実用できない。
そこで
1.videojs を利用 プレーヤhtmlにはbasic認証をかけておく
2.hlsフォルダはreferer制御 refererが同じホストでなければアクセスさせない
/etc/nginx/nginx.conf
#パスワード認証部分(videojsを配置するディレクトリ)
location /live/ {
auth_basic "Hanako Bassic Test";
auth_basic_user_file "/usr/local/nginx/passwd/.htpasswd";
}
#m3u8ファイルができる部分
location ~ ^/hls/ {
valid_referers server_names video.hoge.jp;
if ($invalid_referer) { return 403; }
}
#rtmp の配信を受け hlsに変換する部分
rtmp {
server {
listen 1935;
buflen 30s;
publish_notify on;
drop_idle_publisher 5s;
access_log logs/rtmp_access.log combined;
application live {
live on;
hls on;
hls_path /usr/local/nginx/html/hls;
on_publish http://localhost/publishauth/auth.php;
notify_method get;
on_play http://localhost:8080/on_play;
}
}
/usr/local/nginx/html/live/hls.html
<html>
<head>
<link href="../../live/videojs/video-js.css" rel="stylesheet">
<script src="../../live/videojs/video.js"></script>
<script src="../../live/videojs/videojs-contrib-media-sources.min.js"></script>
<script src="../../live/videojs/videojs-contrib-hls.min.js"></script>
</head>
<body>
<video id="rtmp_div" class="video-js vjs-default-skin" autoplay="autoplay" controls="controls" width="1280" height="720" data-setup="{}">
<source src="http://video.hoge.jp/hls/test.m3u8" type="application/x-mpegURL" />
</video>
</body>
</html>
確認できたブラウザ
iOS Safari,Google Chrome
Windows Edge
m3u8に直接アクセスしても再生できない。
今のところ、Androidでアクセスできず。refererがうまく取れないのかな。referer設定をとったら再生できるようになった。

