2016-08-23 39 views
0

是否可以使用nginx加速标头下载远程文件?我收到的文件没有在Firefox中找到,在Chrome中无效。用nginx加速标头重定向

header("Content-Disposition: attachment; filename= 'asd.zip'"); 
header("Content-Type: application/octet-stream"); 
header('X-Accel-Redirect: http://subdomain.samedomain.com/upload/files/qwe.zip'); 
header("X-Accel-Buffering: yes"); 
header("X-Accel-Limit-Rate: 102400"); 

回答

0

您必须使用proxy_pass代理远程服务器。例如:

header("Content-Disposition: attachment; filename= 'asd.zip'"); 
header("Content-Type: application/octet-stream"); 
header('X-Accel-Redirect: /upload/domain.com/path/to/file.zip'); 
header("X-Accel-Buffering: yes"); 
header("X-Accel-Limit-Rate: 102400"); 

Nginx的

location ~* ^/upload/(.*?)/(.*) { 
    internal; 
    set $download_host $1; 
    set $download_uri $2; 
    proxy_pass http://$download_host/$download_uri; 
} 
+0

远程服务器是动态 – slash197

+0

使用正则表达式来获得主机。 –