starofazeroths 最近的时间轴更新
starofazeroths

starofazeroths

V2EX 第 625280 号会员,加入于 2023-04-21 22:28:22 +08:00
starofazeroths 最近回复了
67 天前
回复了 Elizabevil 创建的主题 程序员 Nginx+HLS 如何防盜鏈
防盜链是一个重要的安全措施,可以保护你的视频内容不被未经授权的网站使用。以下是一些使用 Nginx 和 HLS (HTTP Live Streaming) 实现防盗链的方法:

1. 使用 Referer 检查

在 Nginx 配置中添加 referer 检查:

```nginx
location /hls/ {
valid_referers none blocked server_names *.yourdomain.com yourdomain.com;
if ($invalid_referer) {
return 403;
}
# 其他 HLS 相关配置
}
```

这将只允许来自你指定域名的请求。

2. 使用令牌验证

生成一个带有过期时间的令牌,并在 URL 中包含这个令牌:

```nginx
location /hls/ {
secure_link $arg_md5,$arg_expires;
secure_link_md5 "$secure_link_expires$uri$remote_addr secret";

if ($secure_link = "") {
return 403;
}
if ($secure_link = "0") {
return 410;
}
# 其他 HLS 相关配置
}
```

客户端需要在请求 URL 中包含正确的 md5 和 expires 参数。

3. 使用 Cookie 验证

在用户登录后设置一个 Cookie ,然后在 Nginx 中验证这个 Cookie:

```nginx
location /hls/ {
if ($http_cookie !~* "authorized=1") {
return 403;
}
# 其他 HLS 相关配置
}
```

4. 对 .m3u8 和 .ts 文件进行不同的处理

```nginx
location ~ \.m3u8$ {
# 对 m3u8 文件进行更严格的验证
}

location ~ \.ts$ {
# 对 ts 文件可以稍微宽松一些
}
```

5. 使用加密的 HLS

使用 Apple 的 FairPlay Streaming 或其他 DRM 解决方案来加密你的 HLS 流。

6. 限制 IP 访问频率

```nginx
limit_req_zone $binary_remote_addr zone=one:10m rate=1r/s;

location /hls/ {
limit_req zone=one burst=5;
# 其他 HLS 相关配置
}
```

7. 使用 HTTPS

确保你的 HLS 流通过 HTTPS 提供,这可以防止中间人攻击。

8. 定期更换 URL

对于重要的直播内容,可以考虑定期更换流的 URL 。

实施这些方法时,需要根据你的具体需求和安全级别来选择合适的组合。同时,要注意平衡安全性和用户体验,过于严格的限制可能会影响正常用户的访问。
119 天前
回复了 dzdh 创建的主题 OpenAI 为什么有些中转平台定价比官网便宜那么多?
对了 还有模拟的。比如说是 gpt4 其实是 3.5
119 天前
回复了 dzdh 创建的主题 OpenAI 为什么有些中转平台定价比官网便宜那么多?
还有缓存的吧
119 天前
回复了 proxyai 创建的主题 OpenAI 开源 AI Gateway
有点意思
关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   5594 人在线   最高记录 6679   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 11ms · UTC 06:34 · PVG 14:34 · LAX 23:34 · JFK 02:34
Developed with CodeLauncher
♥ Do have faith in what you're doing.