slash197
slash197

Reputation: 9034

Redirecting with nginx accel headers

Is it possible to download a remote file using nginx accel headers? I'm getting file not found in Firefox and invalid response in Chrome.

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");

Upvotes: 1

Views: 959

Answers (1)

Tan Hong Tat
Tan Hong Tat

Reputation: 6864

You have to use a proxy_pass to proxy to the remote server. Example:

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;
}

Upvotes: 2

Related Questions