Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
php nginx X-Accel-Redirect头文件_Php_Nginx_Http Headers_X Accel Redirect - Fatal编程技术网

php nginx X-Accel-Redirect头文件

php nginx X-Accel-Redirect头文件,php,nginx,http-headers,x-accel-redirect,Php,Nginx,Http Headers,X Accel Redirect,我有一个关于使用nginx用静态文件保护文件夹的问题 因此,基本上我在nginx上设置了根文件夹: /home/rise/rises/wwwdir 而受保护的文件夹是: /home/rise/rises/videop 正如我们所看到的,我将该文件夹移到了根文件夹之外,以防止/允许仅在条件下查看特定内容 当我在发布前第一次进行搜索时,我读到了一些想法,为了访问根目录外的videop文件夹,我需要在nginx conf中创建别名,就像我做的那样 和访问内部 location /videop {

我有一个关于使用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有一个格式错误的头,它应该在
内容类型
之后包含一个


PHP不应该包含一个主体。
readfile
错误。PHP的全部目的是发出内部重定向,该重定向由
nginx
拾取。因此,PHP应该只返回
标题
s。

PHP如何知道
/videop
的根文件夹?也许你应该将绝对路径传递给
readfile
,而不是URL。不工作$aliasedFile='/videop/5_uu.m3u8'$realFile='/home/rise/rises/videop/5_uu.m3u8'$filename='5_u.m3u8';标题(“内容描述:文件传输”);标题(“内容类型:应用程序/x-mpegURL”);标题('Content-Disposition:attachment;filename='.$filename');标题('X-Accel-Redirect:'。$aliasedFile);readfile($realFile);不走运,请不要工作任何人我现在被卡住了5天…有:在内容类型之后查看我以前的帖子,我更改了指令/,我对nginx和这个新别名感到头痛,就像现在我删除别名并在wwdir之后将videop作为目录一样正常工作,我只是想保护那个文件夹,所以我使用了根目录,但与alias结合5天都没有成功,我感到非常非常累,你能pm吗?当你说“一切正常”的时候-它能用你的PHP脚本和
X-Accel-Redirect
一起工作吗?如果是这样,您的新位置块可能没有正确加载到
nginx
。或者,
nginx
用户的文件权限错误。如果删除
内部一切都应该继续工作,除了您可以直接浏览文件-消除PHP脚本(以帮助进一步隔离问题)。不,这是当前的工作代码,但根文件夹中有videop目录,为什么您有
标题(“位置:$file”)在您的工作PHP中?当然,这个头应该只用于重定向。因为这个php页面控制对视频的登录访问,如果可以,则重定向到文件。。