安全的伪流 flv 文件

发布于 2024-12-26 12:20:46 字数 653 浏览 6 评论 0原文

我们使用 RTMP 来保护 Wowza 的流媒体内容,它的作用就像一个魅力。 Wowza 是一个真正强大且健壮的媒体服务器,可用于商业目的。

但我们遇到了一个问题,这个问题对我们来说每天都在变得越来越大。许多新客户由于防火墙规则而无法使用RTMP,为他们提供商业媒体内容是一个问题。 但每个人都没有遇到 http 伪流或渐进式流媒体的问题,就像 youtubevimeo 那样。 因此,我们应该做同样的事情,但提供伪流流量的安全链接,以防止通过窃取链接进行直接下载。

我们使用很少的服务器,一台用于 Rails 应用程序,第二台用于数据库,第三台用作 Wowza 媒体服务器。 我的想法是在 Wowza 媒体服务器上设置 nginx 并配置为伪流媒体原始文件(在 Wowza 用于通过网络摄像头捕获进行流传输的同一文件系统中)。

您能否建议将 nginx 与 http_secure_link_module 和 http_flv_module 模块一起使用? 我同事的另一个想法是在 Wowza 端构建一个小型应用程序来获取加密链接并将其转换到本地文件系统,然后通过 X-Accel-Redirect 访问文件并通过直接连接检查身份验证到数据库。

多谢

We use RTMP to secure stream media content through Wowza and it works like a charm. Wowza is really strong and robust media-server for a business purpose.

But we met a problem, it's getting bigger every day for us. A lot of new customers can't use RTMP by their firewall rules, and it's a problem to deliver a business media content for them.
But everybody has no problems with http pseudo-streaming or just progressive, like it does youtube or vimeo.
So we should do the same, but provide secure links to pseudo-streaming traffic, to prevent a direct download by stealing the links.

We use few servers, one for Rails app, the second for DB, and third as Wowza media server.
My thinking is to setup nginx on Wowza media server and configure to pseudo-stream media originally files (in the same filesystem that Wowza uses to stream through webcam capture).

Can you suggest to use nginx with http_secure_link_module and http_flv_module modules?
Another idea by my colleague is to build a tiny application on Wowza side to get encrypted links and translate it to local file system, then get access to files through X-Accel-Redirect and check authentication via direct connection to DB.

Thanks a lot

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

把昨日还给我 2025-01-02 12:20:46

我找到了解决方案,让我与有兴趣的人分享。

首先,我的限制是尽可能使用最少的工具,因此理想情况下仅在 Web 服务器中具有内置模块,没有上游后端脚本。我现在有一个解决方案。

  server {
      listen       8080 ssl;
      server_name  your_server.com;

      location /video/ {
        rewrite /video/([a-zA-Z0-9_\-]*)/([0-9]*)/(.*)\.flv$ /flv/$3.flv?st=$1&e=$2;
      }

      location /flv/ {
        internal;
        secure_link $arg_st,$arg_e;
        secure_link_md5 YOUR_SECRET_PASSWORD_HERE$arg_e$uri;

        if ($secure_link = "") { return 403; }
        if ($secure_link = "0") { return 403; }

        root /var/www/;
        flv;

        add_header  Cache-Control             'private, max-age=0, must-revalidate';
        add_header  Strict-Transport-Security 'max-age=16070400; includeSubdomains';
      }
}

真正的 flv 文件位于“/var/www/flv”目录中。要在 Ruby 端加密 URL,您可以使用该脚本:

expiration_time = (Time.now + 2.hours).to_i   # 1326559618
s = "#{YOUR_SECRET_PASSWORD_HERE}#{expiration_time}/flv/video1.flv"
a = Base64.encode64(Digest::MD5.digest(s))
b = a.tr("+/", "-_").sub('==', '').chomp    # HLz1px_YzSNcbcaskzA6nQ
# => "http://your_server.com:8080/video/#{b}/#{expiration_time}/video1.flv"

因此安全的 2 小时 URL(您可以将其放入 flash-player 中)如下所示:

"http://your_server.com:8080/video/HLz1px_YzSNcbcaskzA6nQ/1326559618/video1.flv"

PS Nginx 应使用以下选项进行编译 --with-http_secure_link_module --with-http_flv_module

$ cd /usr/src
$ wget http://nginx.org/download/nginx-1.2.2.tar.gz
$ tar xzvf ./nginx-1.2.2.tar.gz && rm -f ./nginx-1.2.2.tar.gz

$ wget http://zlib.net/zlib127.zip
$ unzip zlib127.zip && rm -f zlib127.zip

$ wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.30.tar.gz
$ tar xzvf pcre-8.30.tar.gz && rm -f ./pcre-8.30.tar.gz

$ wget http://www.openssl.org/source/openssl-1.0.1c.tar.gz
$ tar xzvf openssl-1.0.1c.tar.gz && rm -f openssl-1.0.1c.tar.gz

$ cd nginx-1.2.2 && ./configure --prefix=/opt/nginx --with-pcre=/usr/src/pcre-8.30 --with-zlib=/usr/src/zlib-1.2.7 --with-openssl-opt=no-krb5 --with-openssl=/usr/src/openssl-1.0.1c --with-http_ssl_module --without-mail_pop3_module --without-mail_smtp_module --without-mail_imap_module --with-http_stub_status_module --with-http_secure_link_module --with-http_flv_module
$ make && make install

I have found a solution, let me share with anyone interested in it.

First of all, my constraints was to use the minimum tools as possible, so ideally to have built-in module in web-server only, no upstream backend scripts. And I have a solution now.

  server {
      listen       8080 ssl;
      server_name  your_server.com;

      location /video/ {
        rewrite /video/([a-zA-Z0-9_\-]*)/([0-9]*)/(.*)\.flv$ /flv/$3.flv?st=$1&e=$2;
      }

      location /flv/ {
        internal;
        secure_link $arg_st,$arg_e;
        secure_link_md5 YOUR_SECRET_PASSWORD_HERE$arg_e$uri;

        if ($secure_link = "") { return 403; }
        if ($secure_link = "0") { return 403; }

        root /var/www/;
        flv;

        add_header  Cache-Control             'private, max-age=0, must-revalidate';
        add_header  Strict-Transport-Security 'max-age=16070400; includeSubdomains';
      }
}

The real flv files located into "/var/www/flv" directory. To encrypt the URL on Ruby side, you can use that script:

expiration_time = (Time.now + 2.hours).to_i   # 1326559618
s = "#{YOUR_SECRET_PASSWORD_HERE}#{expiration_time}/flv/video1.flv"
a = Base64.encode64(Digest::MD5.digest(s))
b = a.tr("+/", "-_").sub('==', '').chomp    # HLz1px_YzSNcbcaskzA6nQ
# => "http://your_server.com:8080/video/#{b}/#{expiration_time}/video1.flv"

So the secured 2-hours URL (you can put it into flash-player) looks like:

"http://your_server.com:8080/video/HLz1px_YzSNcbcaskzA6nQ/1326559618/video1.flv"

P.S. Nginx should be compiled with following options --with-http_secure_link_module --with-http_flv_module

$ cd /usr/src
$ wget http://nginx.org/download/nginx-1.2.2.tar.gz
$ tar xzvf ./nginx-1.2.2.tar.gz && rm -f ./nginx-1.2.2.tar.gz

$ wget http://zlib.net/zlib127.zip
$ unzip zlib127.zip && rm -f zlib127.zip

$ wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.30.tar.gz
$ tar xzvf pcre-8.30.tar.gz && rm -f ./pcre-8.30.tar.gz

$ wget http://www.openssl.org/source/openssl-1.0.1c.tar.gz
$ tar xzvf openssl-1.0.1c.tar.gz && rm -f openssl-1.0.1c.tar.gz

$ cd nginx-1.2.2 && ./configure --prefix=/opt/nginx --with-pcre=/usr/src/pcre-8.30 --with-zlib=/usr/src/zlib-1.2.7 --with-openssl-opt=no-krb5 --with-openssl=/usr/src/openssl-1.0.1c --with-http_ssl_module --without-mail_pop3_module --without-mail_smtp_module --without-mail_imap_module --with-http_stub_status_module --with-http_secure_link_module --with-http_flv_module
$ make && make install
秉烛思 2025-01-02 12:20:46

当 RTMP 连接失败时,JW 播放器和 Flowplayer 将自动回退到 RTMPT(通过 HTTP),Wowza 使两者都可用。我在多个位置遇到了端口 1935 被阻塞的情况,通过端口 80 回退到 RTMPT 通常可以正常工作。当然,需要注意的是,您必须让 Wowza 侦听端口 80(在定义 1935 的 VHost.xml 中,将其更改为 80,1935),并且这会阻止任何类型的 Web 服务器侦听同一端口港口。

JW player and Flowplayer will automatically fall back to RTMPT (over HTTP) when an RTMP connection is unsuccessful, and Wowza makes both available. I've encountered port 1935 blocked at several locations, and the fallback to RTMPT over port 80 generally works. The caveat there, of course, is that you have to have Wowza listening on port 80 (in the VHost.xml where 1935 is defined, change it to 80,1935), and that precludes having any kind of web server listening on the same port.

昔梦 2025-01-02 12:20:46

我们与客户一起使用带有端口 80 的 Wowza

We use Wowza with port 80 with our clients

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文