【发布时间】:2015-04-29 16:59:10
【问题描述】:
我的配置是带有 nginx 的 php-fpm 5.4。我需要提供一些受保护的文件。因此,我与 Symfony 核对用户是否具有正确的权限,然后我希望 nginx 使用 X-accel-redirect 标头提供文件(swf)。
symfony 中的控制器:
/**
* @Route("/protected/swf")
*/
public function sendFileAction()
{
// [...]
// user rights are ok, serve the file
$fileName = 'myfile.swf';
$filePath = $this->get('kernel')->getRootDir() . '/../files/' . $fileName;
$response = new BinaryFileResponse($filePath);
$response->trustXSendfileTypeHeader();
return $response;
}
还有我的 nginx 配置:(http://wiki.nginx.org/XSendfile)。这些文件位于 web 目录(文件)之外的目录中。
location /files/ {
internal;
root /path/to/folder;
}
它可以工作(我的意思是文件已提供),但我认为它没有使用 XSendfile。如果我理解正确,nginx 将提供一个文件,如果标题
X-Accel-Redirect: /files/myfile.swf;
存在。但是 BinaryFileResponse 使用磁盘上的路径来查找我的文件,并且不知道应该像上面那样设置这个头。
有人可以给我举个例子吗? 谢谢!
【问题讨论】:
标签: symfony nginx x-accel-redirect