getting mp4 mod to work on this config

Christian Andersen christian at andersen.net
Tue Feb 15 00:27:26 MSK 2011


Hey.

How can i implement mp4; on this

Tried many ways, but urls doesnt work when mp4; is added

It will only be .mp4 files on this script.

*nginx.conf code below:*
         location /d/ {
             perl  download::handler;
         }


         # usergroup1
         location /download_f/ {
             alias /disk1/site.com/cgi-bin/uploads/;
             internal;
             set $limit_rate $arg_speed;
             limit_conn one 1;
         }

         # usergroup2
         location /download_r/ {
             alias /disk1/site.com/cgi-bin/uploads/;
             internal;
             set $limit_rate $arg_speed;
             limit_conn one 1;
         }

         # usergroup3
         location /download_p/ {
             alias /disk1/site.com/cgi-bin/uploads/;
             internal;
             set $limit_rate $arg_speed;
             limit_conn one 10;
         }


*download.pm code below:*
package download;
use strict;
use nginx;
use Crypt::HCE_MD5;

my $dl_key = "somekey";
my $upload_dir="/disk1/site.com/cgi-bin/uploads/";

sub handler {
     my $r = shift;

     my $hce = Crypt::HCE_MD5->new($dl_key,"SOMENAME");
     ($_) = $r->filename=~/\/(\w+)\/[^\/]+$/;
     my $l;
     tr|a-z2-7|\0-\37|;
     $_=unpack('B*',$_);
     s/000(.....)/$1/g;
     $l=length;
     $_=substr($_,0,$l & ~7) if $l & 7;
     $_=pack('B*',$_);

     my 
($srv_id,$file_id,$usr_id,$dx,$id,$dmode,$speed,$i1,$i2,$i3,$i4,$expire) 
= unpack("SLLSA12ASC4L", $hce->hce_block_decrypt($_) );
     $dx=sprintf("%05d",$dx);
     $speed = $speed."k" if $speed;

#    if($r->remote_addr !~ /^$i1\.$i2\./)
#    {
#      $r->internal_redirect("/error_wrong_ip.html");
#    }
#elsif($expire<time)
     if($expire<time)
     {
       $r->internal_redirect("/error_expired.html");
     }
     elsif(!-f "$upload_dir/$dx/$id")
     {
       $r->internal_redirect("/error_nofile.html");
     }
     else
     {
       $r->header_out("Content-Disposition","attachment");
       
$r->internal_redirect("/download_$dmode/$dx/$id?id=$file_id&usr=$usr_id&speed=$speed&".$r->args);
     }

     return OK;
}

1;

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://nginx.org/pipermail/nginx/attachments/20110214/4826a594/attachment.html>


More information about the nginx mailing list