php nginx X-Accel-Redirect headers


php nginx X-Accel-Redirect headers

我有一个关于使用nginx用静态文件保护文件夹的问题所以基本上我在nginx上有根文件夹设置为:

/home/rise/rises/wwwdir

安全文件夹为:

/home/rise/rises/videop

正如我们所看到的,我将该文件夹移到了根文件夹之外,以防止/只允许特定的查看标准

当我在发布之前第一次进行搜索时,我读到了一些想法,即要访问根目录之外的videop文件夹,我需要在nginx conf中创建别名,就像我所做的那样并访问内部

location /videop {
        root /home/rise/rises/;
         internal;
        }

然而,我在php方面有一个问题来加载视频。。。

$aliasedFile = '/videop/5_.m3u8';
$filename = '5_.m3u8';
header("Content-Description: File Transfer");
header("Content-Type application/x-mpegURL ");
header('Content-Disposition: attachment; filename='.$filename.'');
header('X-Accel-Redirect: '. $aliasedFile);
readfile($aliasedFile);

我错过了什么?

您的root指令有一个尾随的/,后面跟着URL的前导/,因此使用:

location /videop {
  root /home/rise/rises;
  internal;
}

您的PHP有一个格式不正确的头,应该在Content-Type之后包含一个:

PHP不应该包含正文。readfile错误。PHP的全部目的是发出由nginx获取的内部重定向。因此PHP应该只返回headers。