Welcome! Log In Create A New Profile

Advanced

Не могу добиться работы X-Accel-Redirect

Alex, the Marrch Ca'at
October 21, 2010 03:04PM
Всем доброго времени суток, камрады!

Есть тривиальная, в общем-то, задача: перед скачиванием файлов из
определенной папки показываться пользователю некую страницу, чтобы тот так
или иначе подтвердил, что он имеет право его скачивать. Скрипт отдает
X-Accel-Redirect заголовок после проверки, после чего nginx возвращает 404,
хотя файл есть.

Вот как собран nginx (раньше был 0.6.что-то-там из портов, обновил в попытке
решить проблему):

nginx version: nginx/0.8.53
built by gcc 4.3.2 (Debian 4.3.2-1.1)
TLS SNI support enabled
configure arguments: --conf-path=/etc/nginx/nginx.conf
--error-log-path=/var/log/nginx/error.log --pid-path=/var/run/nginx.pid
--lock-path=/var/lock/nginx.lock --http-log-path=/var/log/nginx/access.log
--http-client-body-temp-path=/var/lib/nginx/body
--http-proxy-temp-path=/var/lib/nginx/proxy
--http-fastcgi-temp-path=/var/lib/nginx/fastcgi --with-debug
--with-http_stub_status_module --with-http_flv_module --with-http_ssl_module
--with-http_dav_module --without-mail_pop3_module --without-mail_imap_module
--without-mail_smtp_module

Вот конфиг:
server {
listen 80;
server_name lmml.name;

access_log /var/log/nginx/lmml.name.access.log;
error_log /var/log/nginx/lmml.name.error.log debug;

location / {
root /var/www/lmml.name/httpdocs;
index index.php index.html index.htm;
}

location /data {
internal;
error_page 404 /download.php?path=$uri;
root /var/www/lmml.name/httpdocs;
}

location ~ \.php$ {
fastcgi_pass unix:/var/run/php-fpm/default.socket;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/
lmml.name/httpdocs$fastcgi_script_name;
include fastcgi_params;
}

location ~ /\.ht {
deny all;
}
}

Вот debug log:

2010/10/21 18:51:08 [debug] 28390#0: *4 http upstream connect: 0

2010/10/21 18:51:08 [debug] 28390#0: *4 http upstream send request

2010/10/21 18:51:08 [debug] 28390#0: *4 chain writer buf fl:0 s:1192

2010/10/21 18:51:08 [debug] 28390#0: *4 chain writer in: 09FACA60

2010/10/21 18:51:08 [debug] 28390#0: *4 writev: 1192

2010/10/21 18:51:08 [debug] 28390#0: *4 chain writer out: 00000000

2010/10/21 18:51:08 [debug] 28390#0: *4 event timer add: 14:
60000:3477507303

2010/10/21 18:51:08 [debug] 28390#0: *4 http finalize request: -4,
"/download.php?path=/data/test.test" a:1, c:3

2010/10/21 18:51:08 [debug] 28390#0: *4 http request count:3 blk:0

2010/10/21 18:51:08 [debug] 28390#0: *4 http finalize request: -4,
"/download.php?path=/data/test.test" a:1, c:2

2010/10/21 18:51:08 [debug] 28390#0: *4 http request count:2 blk:0

2010/10/21 18:51:08 [debug] 28390#0: *4 post event B7B7A0A4

2010/10/21 18:51:08 [debug] 28390#0: *4 delete posted event B7B7A0A4

2010/10/21 18:51:08 [debug] 28390#0: *4 http upstream request:
"/download.php?path=/data/test.test"

2010/10/21 18:51:08 [debug] 28390#0: *4 http upstream dummy handler

2010/10/21 18:51:08 [debug] 28390#0: *4 post event B7BAF0A4

2010/10/21 18:51:08 [debug] 28390#0: *4 post event B7B7A0A4

2010/10/21 18:51:08 [debug] 28390#0: *4 delete posted event B7B7A0A4

2010/10/21 18:51:08 [debug] 28390#0: *4 http upstream request:
"/download.php?path=/data/test.test"

2010/10/21 18:51:08 [debug] 28390#0: *4 http upstream dummy handler

2010/10/21 18:51:08 [debug] 28390#0: *4 delete posted event B7BAF0A4

2010/10/21 18:51:08 [debug] 28390#0: *4 http upstream request:
"/download.php?path=/data/test.test"

2010/10/21 18:51:08 [debug] 28390#0: *4 http upstream process header

2010/10/21 18:51:08 [debug] 28390#0: *4 malloc: 09FACCD8:4096

2010/10/21 18:51:08 [debug] 28390#0: *4 recv: fd:14 184 of 4096

2010/10/21 18:51:08 [debug] 28390#0: *4 http fastcgi record byte: 01

2010/10/21 18:51:08 [debug] 28390#0: *4 http fastcgi record byte: 06

2010/10/21 18:51:08 [debug] 28390#0: *4 http fastcgi record byte: 00

2010/10/21 18:51:08 [debug] 28390#0: *4 http fastcgi record byte: 01

2010/10/21 18:51:08 [debug] 28390#0: *4 http fastcgi record byte: 00

2010/10/21 18:51:08 [debug] 28390#0: *4 http fastcgi record byte: 9D

2010/10/21 18:51:08 [debug] 28390#0: *4 http fastcgi record byte: 03

2010/10/21 18:51:08 [debug] 28390#0: *4 http fastcgi record byte: 00

2010/10/21 18:51:08 [debug] 28390#0: *4 http fastcgi record length: 157

2010/10/21 18:51:08 [debug] 28390#0: *4 http fastcgi parser: 0

2010/10/21 18:51:08 [debug] 28390#0: *4 http fastcgi header: "X-Powered-By:
PHP/5.2.6-1+lenny4.fpm.4"

2010/10/21 18:51:08 [debug] 28390#0: *4 http fastcgi parser: 0

2010/10/21 18:51:08 [debug] 28390#0: *4 http fastcgi header:
"X-Accel-Redirect: /data/test.test"

2010/10/21 18:51:08 [debug] 28390#0: *4 http fastcgi parser: 0

2010/10/21 18:51:08 [debug] 28390#0: *4 http fastcgi header: "Content-type:
"

2010/10/21 18:51:08 [debug] 28390#0: *4 http fastcgi parser: 0

2010/10/21 18:51:08 [debug] 28390#0: *4 http fastcgi header:
"Content-Disposition: attachment; filename="test.test""

2010/10/21 18:51:08 [debug] 28390#0: *4 http fastcgi parser: 1

2010/10/21 18:51:08 [debug] 28390#0: *4 http fastcgi header done

2010/10/21 18:51:08 [debug] 28390#0: *4 finalize http upstream request: -5

2010/10/21 18:51:08 [debug] 28390#0: *4 finalize http fastcgi request

2010/10/21 18:51:08 [debug] 28390#0: *4 free rr peer 1 0

2010/10/21 18:51:08 [debug] 28390#0: *4 close http upstream connection: 14

2010/10/21 18:51:08 [debug] 28390#0: *4 event timer del: 14: 3477507303

2010/10/21 18:51:08 [debug] 28390#0: *4 internal redirect:
"/data/test.test?"

2010/10/21 18:51:08 [debug] 28390#0: *4 rewrite phase: 0

2010/10/21 18:51:08 [debug] 28390#0: *4 test location: "/"

2010/10/21 18:51:08 [debug] 28390#0: *4 test location: "data"

2010/10/21 18:51:08 [debug] 28390#0: *4 test location: ~ "\.php$"

2010/10/21 18:51:08 [debug] 28390#0: *4 test location: ~ "/\.ht"

2010/10/21 18:51:08 [debug] 28390#0: *4 using configuration "/data"

2010/10/21 18:51:08 [debug] 28390#0: *4 http cl:-1 max:1048576

2010/10/21 18:51:08 [debug] 28390#0: *4 rewrite phase: 2

2010/10/21 18:51:08 [debug] 28390#0: *4 post rewrite phase: 3

2010/10/21 18:51:08 [debug] 28390#0: *4 generic phase: 4

2010/10/21 18:51:08 [debug] 28390#0: *4 generic phase: 5

2010/10/21 18:51:08 [debug] 28390#0: *4 access phase: 6

2010/10/21 18:51:08 [debug] 28390#0: *4 access phase: 7

2010/10/21 18:51:08 [debug] 28390#0: *4 post access phase: 8

2010/10/21 18:51:08 [debug] 28390#0: *4 content phase: 9

2010/10/21 18:51:08 [debug] 28390#0: *4 content phase: 10

2010/10/21 18:51:08 [debug] 28390#0: *4 content phase: 11

2010/10/21 18:51:08 [debug] 28390#0: *4 content phase: 12

2010/10/21 18:51:08 [debug] 28390#0: *4 http filename: "/var/www/
lmml.name/httpdocs/data/test.test"

2010/10/21 18:51:08 [debug] 28390#0: *4 add cleanup: 09FACC2C

2010/10/21 18:51:08 [debug] 28390#0: *4 http static fd: 14

2010/10/21 18:51:08 [debug] 28390#0: *4 http set discard body

2010/10/21 18:51:08 [debug] 28390#0: *4 posix_memalign: 09FADCE0:4096 @16

2010/10/21 18:51:08 [debug] 28390#0: *4 HTTP/1.1 404 Not Found

Server: nginx/0.8.53

Date: Thu, 21 Oct 2010 14:51:08 GMT

Content-Type: application/octet-stream

Content-Length: 4

Connection: keep-alive

Content-Disposition: attachment; filename="testwww-lmml-rutest"

2010/10/21 18:51:08 [debug] 28390#0: *4 write new buf t:1 f:0 09FADD74, pos
09FADD74, size: 233 file: 0, size: 0

2010/10/21 18:51:08 [debug] 28390#0: *4 http write filter: l:0 f:0 s:233

2010/10/21 18:51:08 [debug] 28390#0: *4 http output filter
"/data/test.test?"

2010/10/21 18:51:08 [debug] 28390#0: *4 http copy filter: "/data/test.test?"

2010/10/21 18:51:08 [debug] 28390#0: *4 http postpone filter
"/data/test.test?" BFEE6B08

2010/10/21 18:51:08 [debug] 28390#0: *4 write old buf t:1 f:0 09FADD74, pos
09FADD74, size: 233 file: 0, size: 0

2010/10/21 18:51:08 [debug] 28390#0: *4 write new buf t:0 f:1 00000000, pos
00000000, size: 0 file: 0, size: 4

2010/10/21 18:51:08 [debug] 28390#0: *4 http write filter: l:1 f:0 s:237

2010/10/21 18:51:08 [debug] 28390#0: *4 http write filter limit 0

2010/10/21 18:51:08 [debug] 28390#0: *4 writev: 233

2010/10/21 18:51:08 [debug] 28390#0: *4 sendfile: @0 4

2010/10/21 18:51:08 [debug] 28390#0: *4 sendfile: 4, @0 4:4

2010/10/21 18:51:08 [debug] 28390#0: *4 http write filter 00000000

2010/10/21 18:51:08 [debug] 28390#0: *4 http copy filter: 0
"/data/test.test?"

2010/10/21 18:51:08 [debug] 28390#0: *4 http finalize request: 0,
"/data/test.test?" a:1, c:2

2010/10/21 18:51:08 [debug] 28390#0: *4 http request count:2 blk:0

2010/10/21 18:51:08 [debug] 28390#0: *4 http finalize request: -4,
"/data/test.test?" a:1, c:1

2010/10/21 18:51:08 [debug] 28390#0: *4 set http keepalive handler

2010/10/21 18:51:08 [debug] 28390#0: *4 http close request

2010/10/21 18:51:08 [debug] 28390#0: *4 http log handler

2010/10/21 18:51:08 [debug] 28390#0: *4 run cleanup: 09FACC2C

2010/10/21 18:51:08 [debug] 28390#0: *4 file cleanup: fd:14

2010/10/21 18:51:08 [debug] 28390#0: *4 free: 09FACCD8

2010/10/21 18:51:08 [debug] 28390#0: *4 free: 09FABCC0, unused: 4

2010/10/21 18:51:08 [debug] 28390#0: *4 free: 09FADCE0, unused: 3382

2010/10/21 18:51:08 [debug] 28390#0: *4 event timer add: 13:
65000:3477512305

2010/10/21 18:51:08 [debug] 28390#0: *4 free: 09FA3908

2010/10/21 18:51:08 [debug] 28390#0: *4 free: 09FA3500

2010/10/21 18:51:08 [debug] 28390#0: *4 hc free: 00000000 0

2010/10/21 18:51:08 [debug] 28390#0: *4 hc busy: 00000000 0

2010/10/21 18:51:08 [debug] 28390#0: *4 post event B7BAF070

2010/10/21 18:51:08 [debug] 28390#0: *4 delete posted event B7BAF070

2010/10/21 18:51:08 [debug] 28390#0: *4 http keepalive handler

2010/10/21 18:51:08 [debug] 28390#0: *4 malloc: 09FA3500:1024

2010/10/21 18:51:08 [debug] 28390#0: *4 recv: fd:13 -1 of 1024

2010/10/21 18:51:08 [debug] 28390#0: *4 recv() not ready (11: Resource
temporarily unavailable)

2010/10/21 18:52:13 [debug] 28390#0: *4 event timer del: 13: 3477512305

2010/10/21 18:52:13 [debug] 28390#0: *4 http keepalive handler
2010/10/21 18:52:13 [debug] 28390#0: *4 close http connection: 13

- видно, что получив ответ от FCGI, nginx правильно определил путь к файлу,
но после этого почему-то вернул 404. Что происходит - понять не могу.

При этом я ровно такую же схему совсем недавно уже реализовывал на другом
серваке, и там все работало правильно. К сожалению, того сервера уже нет в
живых, чтобы сравнить и понять, в чем отличие...

Буду благодарен за любые конструктивные идеи и подсказки!

Алекс Марртовский.
_______________________________________________
nginx-ru mailing list
nginx-ru@nginx.org
http://nginx.org/mailman/listinfo/nginx-ru
Subject Author Posted

Не могу добиться работы X-Accel-Redirect

Alex, the Marrch Ca'at October 21, 2010 03:04PM

Re: Не могу добиться работы X-Accel-Redirect

Maxim Dounin October 21, 2010 04:58PM

Re: Не могу добиться работы X-Accel-Redirect

Alex, the Marrch Ca'at October 21, 2010 05:28PM

Re: Не могу добиться работы X-Accel-Redirect

Alex, the Marrch Ca'at October 21, 2010 05:36PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 266
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready