php nginx X-Accel-Redirect标头

时间:2015-11-23 11:00:12

标签: php nginx http-headers x-accel-redirect

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

/home/rise/rises/wwwdir

并且安全文件夹是:

/home/rise/rises/videop

我们可以看到我将该文件夹移到根文件夹之外以防止/仅允许特定于标准

下查看

当我在发布之前首次进行搜索时,我读了一些想要访问root之外的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);

我错过了什么?

1 个答案:

答案 0 :(得分:0)

您的root指令后跟/,后面跟着网址的前导/,请使用:

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

您的PHP包含格式错误的标头,在:之后应包含Content-Type

PHP不应该包含正文。 readfile错了。 PHP的全部目的是发出由nginx选取的内部重定向。所以PHP应该仅返回header

相关问题