duanfan9859 2019-04-23 07:26
浏览 270

为什么nginx在我的PHP文件下载中返回403?

I use nginx 1.14.1 with PHP and I have problems with a call that should result in a file download.

The PHP application produces a response with status code 200 and the file contents are dumped in the body, but from nginx I get the following answer (head)

HTTP/2 403 
server: nginx/1.14.1
date: Tue, 23 Apr 2019 07:19:19 GMT
content-type: text/html; charset=UTF-8
vary: Accept-Encoding
x-powered-by: PHP/7.2.17
strict-transport-security: max-age=31536000

The headers my PHP application produces are not included in the nginx response.

Firefox yields the error "/Users/myuser/Downloads/NBPKD9pN.mp4.part could not be saved, because the source file could not be read. Try again later, or contact the server administrator."

The file that should be downloaded is about 1 GB in size.

The rest of the PHP application works fine (does not result in 403s).

Does it help to provide my full nginx config?

When I put the same file into the web root and call it directly (without PHP) the download works fine.

Edit: The PHP code roughly looks like this:

header('Content-Type: video/mp4');
header('Content-Disposition: attachment; filename="' . $filename . '"');
header('Content-Length: ' . $filesize));
readfile($file);
die();
  • 写回答

1条回答 默认 最新

  • dpepbjp126917 2019-04-23 08:37
    关注

    The problem was that the PHP application has used ob_start() at some earlier point so the output of readfile() landed in the memory, which exceeded its limit.

    评论

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题