首页 > 解决方案 > Nginx 只允许我的域访问视频 url

问题描述

我正在设置一个 Web 服务器,其中包含嵌入到 html5 视频标签中的实时视频流。我的工作流程是从网络摄像机中获取 rtsp 视频,使用 ffmpeg 将其解码为 HLS 格式,然后将视频发送到我的服务器。Nginx 允许通过 url 访问视频,我将其作为来源放入我的视频标签中。

一切正常,唯一的问题是任何人都可以在未经我许可的情况下访问视频的 URL 并将该 URL 放在他们的网站上。

有没有办法只允许我的域访问,并阻止例如 www.domain2.com 将其放入他们使用的视频标签或其他框架中?我认为 Nginx 也许可以完成这项工作。

这是 Nginx 的代码和我的 html 以防万一。

HTML:

<video id="player" class="video-js vjs-default-skin vjs-big-play-centered vjs-fluid"  controls preload="none">
<source src="//mydomain.com/live/stream.m3u8" type="application/x-mpegURL" />

Nginx:

location /live {
            types {
                    application/vnd.apple.mpegurl m3u8;
            }
            limit_conn addr 5;
            alias /home/stream;
            add_header Cache-Control no-cache;
            add_header 'Access-Control-Allow-Origin' '*';
    }

非常感谢你们!

标签: nginxvideoffmpeghtml5-videohttp-live-streaming

解决方案


如果你有一个固定的 IP,你可以在 nginx 块中使用允许拒绝命令,你可以在这里查看如何使用它http://etapien.com/guides/nginx-allow-access-certain-ips/

location /live {
    types {
        application/vnd.apple.mpegurl m3u8;
    }
    # .. some config

    allow 192.168.1.0/24; #your company subaddress
    allow 10.1.1.0/16;  #your company IP
    deny all;
}

推荐阅读