0

I have the following block in my nginx config:

location /files {
    internal;
    root /var/www/website/storage/uploads;
}

In my Laravel app I am trying to redirect get-file URI to the private internal /files route (The get-file URI triggers the following PHP method get_file):

public function get_file(Request $request)
{
    $path_to_file = "/files/image.jpg"
    return response('')->header('X-Accel-Redirect', $path_to_file);
}

But I get 404 Not Found from nginx (with the nginx error page).

And the file image.jpg exists in /var/www/website/storage/uploads/

1 Answer 1

0

I found the issue:

I needed to change the nginx block configuration to the following:

location /uploads {
    internal;
    root /var/www/website/storage/;
}

And the PHP code to the following:

public function get_file(Request $request)
{
    $path_to_file = "/uploads/image.jpg"
    return response('')->header('X-Accel-Redirect', $path_to_file);
}

Because with the original block it would try to serve /var/www/website/storage/uploads/files/image.jpg;

I had a confusion with alias and root

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .