[英]How do i use Apache for Upload and Nginx for Secure Download
I have a website, for file sharing which is in perl, now there is file index.dl which is used for download request. 我有一个网站,用于在perl中进行文件共享,现在有用于下载请求的文件index.dl。 In apache it creates a very high load, the load goes almost at 100.
在apache中,它会产生非常高的负载,负载几乎达到100。
Now i can not use nginx proxy. 现在我不能使用Nginx代理。
I want to set apache to handle all the uploads, and nginx to handle the download requests. 我想设置apache来处理所有上载,并设置nginx来处理下载请求。
I have checked there is a module "http-secure-link-module" so i have installed that as well. 我已经检查了有一个模块“ http-secure-link-module”,所以我也已经安装了它。
Now our site generates the file download link like 现在我们的网站生成文件下载链接,例如
xyz.com/d/$hash/filename.xyz xyz.com/d/$hash/filename.xyz
now this is the code that generates the link 现在这是生成链接的代码
sub genDirectLink
{
my ($file,$mode,$mins,$fname)=@_;
require HCE_MD5;
my $hce = HCE_MD5->new($c->{dl_key},"mysecret");
my $usr_id = $ses->getUser ? $ses->getUserId : 0;
my $dx = sprintf("%d",($file->{file_real_id}||$file->{file_id})/$c->{files_per_folder});
my $hash = &encode32( $hce->hce_block_encrypt(pack("SLLSA12ASC4L",
$file->{srv_id},
$file->{file_id},
$usr_id,
$dx,
$file->{file_real},
$mode||'f',
$c->{down_speed},
split(/\./,$ses->getIP),
time+60*$mins)) );
#$file->{file_name}=~s/%/%25/g;
#$file->{srv_htdocs_url}=~s/\/files//;
my ($url) = $file->{srv_htdocs_url}=~/(http:\/\/.+?)\//i;
$fname||=$file->{file_name};
return "$url:182/d/$hash/$fname";
}
sub encode32
{
$_=shift;
my($l,$e);
$_=unpack('B*',$_);
s/(.....)/000$1/g;
$l=length;
if($l & 7)
{
$e=substr($_,$l & ~7);
$_=substr($_,0,$l & ~7);
$_.="000$e" . '0' x (5-length $e);
}
$_=pack('B*', $_);
tr|\0-\37|A-Z2-7|;
lc($_);
}
and i have setup my nginx config as 我已经将我的nginx配置设置为
server {
listen 182;
server_name myhost.com www.myhost.com;
location / {
root /home/user/domains/hostname.com/public_html/files;
}
location /d/ {
secure_link_secret mysecret;
if ($secure_link = "") {
return 403;
}
rewrite ^ /files/$secure_link;
}
location /files/ {
internal;
}
}
So now the problem is, when i tried to visit any link, it gives 404 error. 所以现在的问题是,当我尝试访问任何链接时,它会显示404错误。 how do i get file download working?
我如何才能下载文件?
this directive secure_link_secret
, has been deprecated as of nginx 0.8.50, see: http://wiki.nginx.org/HttpSecureLinkModule 从nginx 0.8.50开始不推荐使用此指令
secure_link_secret
,请参阅: http ://wiki.nginx.org/HttpSecureLinkModule
I made a code using the correct directive: 我使用正确的指令编写了代码:
server {
listen 182;
server_name example.com;
location / {
root /home/fileshare/domains/fileshare4u.com/public_html/files;
}
location ~^/d/(?P<hash>[^\/]+)/(?P<url>.*)$ {
secure_link $hash,$arg_e;
secure_link_md5 KEY$url$arg_e;
if ($secure_link = "") {
return 403;
}
if ($secure_link = "0") {
return 403;
}
rewrite ^ /files/$url last;
}
location /files/ {
alias /tmp/;
internal;
}
}
perl hash generate: perl哈希生成:
use Digest::MD5 qw(md5 md5_hex md5_base64);
# http://search.cpan.org/~kazuho/MIME-Base64-URLSafe-0.01/lib/MIME/Base64/URLSafe.pm
use MIME::Base64::URLSafe;
$uri = "sitemap_artistas_1.xml.gz"; # FILE NAME
$key = "KEY"; # KEY
$expire = time() + 30; # 30s
$hash = urlsafe_b64encode(md5("$key$uri$expire"));
$domain = "example.com";
$port = "182";
return "http://$domain:$port/d/$hash/$uri?e=$expire";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.