Nginx Как работает X-Accel-Redirect?

hell0w0rd

Продвинутый новичок
У меня он не работает никак. Попробовал по всякому, вот как сделал на vps (вдруг osx глючит).
PHP:
// /home/nkt/test.js
var http = require('http');

http.createServer(function (req, res) {
    res.setHeader('X-Accel-Redirect', '/test.js');
    res.end();
}).listen(3333);
PHP:
// nginx
  server {
        listen localhost:4000;
        server_name localhost;
        root /home/nkt;

        location / {
            internal;
            proxy_pass http://127.0.0.1:3333;
        }
    }
Код:
$ node test.js &
[1] 1912

$ curl -v http://localhost:3333/
* Hostname was NOT found in DNS cache
*  Trying ::1...
* connect to ::1 port 3333 failed: Connection refused
*  Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 3333 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.35.0
> Host: localhost:3333
> Accept: */*
>
< HTTP/1.1 200 OK
< X-Accel-Redirect: /test.js
< Date: Mon, 09 Mar 2015 19:13:48 GMT
< Connection: keep-alive
< Transfer-Encoding: chunked
<
* Connection #0 to host localhost left intact

$ curl -v http://localhost:4000/
* Hostname was NOT found in DNS cache
*  Trying ::1...
* connect to ::1 port 4000 failed: Connection refused
*  Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 4000 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.35.0
> Host: localhost:4000
> Accept: */*
>
< HTTP/1.1 404 Not Found
* Server nginx is not blacklisted
< Server: nginx
< Date: Mon, 09 Mar 2015 19:13:58 GMT
< Content-Type: text/html
< Content-Length: 162
< Connection: keep-alive
<
<html>
<head><title>404 Not Found</title></head>
<body bgcolor="white">
<center><h1>404 Not Found</h1></center>
<hr><center>nginx</center>
</body>
</html>
* Connection #0 to host localhost left intact
Что я делаю не так?
 

AnrDaemon

Продвинутый новичок
Пытаешься редиректить на самого себя.
nginx не настолько идиот, всё же.

А, не, извини, я что-то не то прочёл.
 

fixxxer

К.О.
Партнер клуба
ты не понял.

PHP:
server {

        location / {
            root /path/to/root;
            proxy_pass http://127.0.0.1:3333;
        }

        location /_xar_/ {
            internal;
            alias /path/to/root;
        }
PHP:
res.setHeader('X-Accel-Redirect', '/_xar_/test.js');
 
Последнее редактирование:

fixxxer

К.О.
Партнер клуба
Кстати, если мусорить в неймспейс uri для задачи не ок, в последних версиях можно как-то так (не проверял, но должно работать; заодно - пример эмуляции X-Sendfile из лайти):

PHP:
location @sendfile {
     internal;
     alias /$upstream_http_x_sendfile;
}
....
res.setHeader('X-Accel-Redirect', '@sendfile');
res.setHeader('X-Sendfile', '/var/tmp/filename.ext');
 
Сверху