2016-08-23 111 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

使用正則表達式來獲得主機。 –