douli2876 2016-08-23 06:07
浏览 90
已采纳

使用nginx加速标头重定向

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");
  • 写回答

1条回答 默认 最新

  • dsjq6977 2016-08-23 06:33
    关注

    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;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 本地测试网站127.0.0.1 已拒绝连接,如何解决?(标签-ubuntu)
  • ¥50 Qt在release捕获异常并跟踪堆栈(有Demo,跑一下环境再回答)
  • ¥30 python,LLM 文本提炼
  • ¥15 关于将inet引入的相关问题
  • ¥15 关于一个倒计时的操作和显示设计
  • ¥15 提问STK的问题,哪位航天领域的同学会啊
  • ¥15 苹果系统的mac m1芯片的笔记本使用ce修改器使用不了
  • ¥15 单相逆变的电压电流双闭环中进行低通滤波PID算法改进
  • ¥15 关于#java#的问题,请各位专家解答!
  • ¥15 如何卸载arcgis 10.1 data reviewer for desktop