简体   繁体   English

X-Accel-Redirect 的内部重定向别名错误

[英]Wrong internal redirect alias for X-Accel-Redirect

Nginx internal redirect file search in wrong path. Nginx 内部重定向文件搜索路径错误。

I'm using nginx and laravel(PHP) and want to doing secure online storage.if user exist and has permission, user can download file.我正在使用 nginx 和 laravel(PHP) 并且想要进行安全的在线存储。如果用户存在并且有权限,用户可以下载文件。 I'm use 'X-Accel-Redirect' for this action.我为此操作使用“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 nginx 配置

    root /var/www/public;
#...
    location /storage/ {
      alias /var/www/storage/;
      internal;
    }
#also i tried root key same result not changed

I think alias didnt overwrite to parent scope root key but i dindt solve that.我认为别名没有覆盖父 scope 根密钥,但我没有解决这个问题。

Nginx Log ---
[error] 35#35: *1 open() "/var/www/public/storage/app/public/4.jpg" failed (2: No such file or directory),

normaly file stored in /var/www/storage/app/public/4.jpg normaly 文件存储在 /var/www/storage/app/public/4.jpg

I fixed it with nginx conf.我用 nginx conf 修复了它。 nginx didnt catch to url so i change with these configuration nginx 没有赶上 url 所以我改变了这些配置

 location ^~ /storage/ {
      alias /var/www/storage/;
      internal;
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM