C
C
criminalist2019-05-07 08:05:26
Nginx
criminalist, 2019-05-07 08:05:26

Correct paths for header('X-Accel-Redirect:?

Hello, the question is why when I send the header
header("X-Accel-Redirect: $filename");
The $filename variable is equal to "/usr/home/www/site.ru/uload/file/id/name.rar"
That is, the path is correct and everything is in order, but we get an error on the pages, go to nginx.log and see this path

/usr/home/www/site.ru/usr/home/www/site.ru/uload/file/id/name.rar

After all, this is not what I am transmitting, I double-checked everything 100500 times, I suppose there is a problem with nginx.conf
in it, if you rely on articles, there should be a section
location /download {
      internal;
}

I didn’t register it, because I have each file in a separate folder by ID, I couldn’t understand how to create such a location.
Does anyone have experience can tell me where to drip?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
ivankomolin, 2019-05-07
@ivankomolin

You must pass a URI to the X-Accel-Redirect header
Example:
Nginx has a location:

location /download {
      internal;
}

This means that in X-Accel-Redirect it is necessary to pass the url that this particular location will process:
In general, in order to implement such things, you must first understand how nginx works, at least understand how nginx processes requests and how its config affects it.
In your case, it is obvious that you are passing the url that nginx concatenates with some root on the server in the location of which it got.

C
criminalist, 2019-05-07
@criminalist

In general, the issue was resolved, I didn’t do the location at all, I registered the file name in PHP, the root was taken from ROOT in nginx
header("X-Accel-Redirect: $filepath);
As a result, the correct path turned out, for a number of reasons and unwillingness to change something in the site engine managed in this way.Thanks to
everyone who responded.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question