phpnginxx-sendfilex-accel-redirect

Wrong internal redirect alias for X-Accel-Redirect


Nginx internal redirect file search in wrong path.

I'm using nginx and laravel(PHP) and want to doing secure online storage.if user exist and has permission, user can download file. I'm use 'X-Accel-Redirect' for this action.

    //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

I think alias didnt overwrite to parent scope root key but i dindt solve that.

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


Solution

  • I fixed it with nginx conf. nginx didnt catch to url so i change with these configuration

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