nginx - 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' '*';
}
非常感谢你们!
解决方案
如果你有一个固定的 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;
}
推荐阅读
- html - 无法在我购买的 html 中找到网站上的图像链接。我拥有它,但它在哪里?
- c# - Http Get 请求没有得到任何数据
- c# - Unity3D中Transform的具体用途是什么?和我正在处理的代码示例
- angular - 当我尝试构建我的 ionic 应用程序时,构建 gradle 出现问题
- python-3.x - mac终端中的“python”和“pythonw”有什么区别?
- firemonkey - GPS 文件属性 (FMX)
- sockets - 在 Flutter 中显示图像,通过套接字连接发送
- javascript - 循环画廊使用 next() 和 prev() 方法的问题 - javascript / jQuery
- c# - 使用承载令牌验证 MVC 控制器并重定向到控制器
- android - 如何通过添加部分来重构 Android Studio 上的 Android 包名称?