Nginx内部重定向文件搜索路径错误。
我正在使用nginx和laravel(PHP),想做安全的在线storage.if用户存在并有权限,用户可以下载文件。我使用'X-Accel-Redirect‘来执行此操作。
//it works with apache X-Sendfile
public function download()
{
$filename = "4.jpg";
return response(null)
->header('Content-Disposition', 'attachment; filename="' . $filename . '"')
->header('X-Accel-Redirect', "/storage/app/public/$filename")
->header('X-Sendfile', base_path("storage/app/public/$filename"));
}nginx conf
root /var/www/public;
#...
location /storage/ {
alias /var/www/storage/;
internal;
}
#also i tried root key same result not changed我认为别名没有覆盖到父作用域根键,但我没有解决这个问题。
Nginx Log ---
[error] 35#35: *1 open() "/var/www/public/storage/app/public/4.jpg" failed (2: No such file or directory),存储在/var/www/storage/app/public/4.jpg中的普通文件
发布于 2019-09-29 10:13:20
我用nginx conf修复了它。nginx没有捕获到url,所以我使用这些配置进行了更改
location ^~ /storage/ {
alias /var/www/storage/;
internal;
}https://stackoverflow.com/questions/58148986
复制相似问题