我在 Windows 7 上的nginx 1.4.4,php 5.5.8(来自WT-NMP)上使用sendfile。我在配置中有这两个位置。
location ^~ /upload_folder/ {
internal;
alias "c:/WT-NMP/WWW/m24/upload/";
}
location ~ \.(js|css|png|jpg|gif|swf|ico|pdf|mov|fla|zip|rar|woff|ttf|svg|otf|mp3)$ {
try_files $uri =404;
}
当我将标题设置为
时X-Accel-Redirect: \upload_folder\Z5lvSRzMLxjNZZx6xJb70GiCTNKM8ZqP.jpg
然后测试第一个位置,看起来它在我的磁盘上找到了正确的文件。但是还有另一个位置测试,现在第二个位置匹配,但正如我在文档中读到的那样,搜索位置应该停止,因为我在 / upload_folder ^〜前缀>位置。为什么nginx测试第二个位置的位置?在Linux上有一个非常相似的配置,但它按预期工作。
我的日志中有一些最重要的行:
2014/03/27 14:14:04 [debug] 11116#12652: *766 test location: "/"
2014/03/27 14:14:04 [debug] 11116#12652: *766 test location: "upload_folder/"
2014/03/27 14:14:04 [debug] 11116#12652: *766 test location: ~ "/themes/\w+/views"
2014/03/27 14:14:04 [debug] 11116#12652: *766 test location: ~ "\. (js|css|png|jpg|gif|swf|ico|pdf|mov|fla|zip|rar|woff|ttf|svg|otf|mp3)$"
2014/03/27 14:14:04 [debug] 11116#12652: *766 test location: ~ "\.php$"
2014/03/27 14:14:04 [debug] 11116#12652: *766 using configuration "\.php$"
.
.
2014/03/27 14:14:04 [debug] 11116#12652: *766 http fastcgi parser: 0
2014/03/27 14:14:04 [debug] 11116#12652: *766 http fastcgi header: "X-Powered-By: PHP/5.5.8"
2014/03/27 14:14:04 [debug] 11116#12652: *766 http fastcgi parser: 0
2014/03/27 14:14:04 [debug] 11116#12652: *766 http fastcgi header: "Expires: Thu, 19 Nov 1981 08:52:00 GMT"
2014/03/27 14:14:04 [debug] 11116#12652: *766 http fastcgi parser: 0
2014/03/27 14:14:04 [debug] 11116#12652: *766 http fastcgi header: "Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0"
2014/03/27 14:14:04 [debug] 11116#12652: *766 http fastcgi parser: 0
2014/03/27 14:14:04 [debug] 11116#12652: *766 http fastcgi header: "Pragma: no-cache"
2014/03/27 14:14:04 [debug] 11116#12652: *766 http fastcgi parser: 0
2014/03/27 14:14:04 [debug] 11116#12652: *766 http fastcgi header: "Content-Type: image/jpeg"
2014/03/27 14:14:04 [debug] 11116#12652: *766 http fastcgi parser: 0
2014/03/27 14:14:04 [debug] 11116#12652: *766 http fastcgi header: "Content-Disposition: attachment; filename="testfile.jpg""
2014/03/27 14:14:04 [debug] 11116#12652: *766 http fastcgi parser: 0
2014/03/27 14:14:04 [debug] 11116#12652: *766 http fastcgi header: "X-Accel-Redirect: \upload_folder\Z5lvSRzMLxjNZZx6xJb70GiCTNKM8ZqP.jpg"
2014/03/27 14:14:04 [debug] 11116#12652: *766 http fastcgi parser: 0
.
.
2014/03/27 14:14:04 [debug] 11116#12652: *766 internal redirect: "\upload_folder\Z5lvSRzMLxjNZZx6xJb70GiCTNKM8ZqP.jpg?"
2014/03/27 14:14:04 [debug] 11116#12652: *766 rewrite phase: 1
2014/03/27 14:14:04 [debug] 11116#12652: *766 test location: "/"
2014/03/27 14:14:04 [debug] 11116#12652: *766 test location: ~ "/themes/\w+/views"
2014/03/27 14:14:04 [debug] 11116#12652: *766 test location: ~ "\.(js|css|png|jpg|gif|swf|ico|pdf|mov|fla|zip|rar|woff|ttf|svg|otf|mp3)$"
2014/03/27 14:14:04 [debug] 11116#12652: *766 using configuration "\.(js|css|png|jpg|gif|swf|ico|pdf|mov|fla|zip|rar|woff|ttf|svg|otf|mp3)$"
.
.
2014/03/27 14:14:04 [debug] 11116#12652: *766 try files phase: 11
2014/03/27 14:14:04 [debug] 11116#12652: *766 http script var: "\upload_folder\Z5lvSRzMLxjNZZx6xJb70GiCTNKM8ZqP.jpg"
2014/03/27 14:14:04 [debug] 11116#12652: *766 trying to use file: "\upload_folder\Z5lvSRzMLxjNZZx6xJb70GiCTNKM8ZqP.jpg" "c:/wt-nmp/www/m24/web\upload_folder\Z5lvSRzMLxjNZZx6xJb70GiCTNKM8ZqP.jpg"
2014/03/27 14:14:04 [debug] 11116#12652: *766 trying to use file: "=404" "c:/wt-nmp/www/m24/web=404"
2014/03/27 14:14:04 [debug] 11116#12652: *766 http finalize request: 404, "\upload_folder\Z5lvSRzMLxjNZZx6xJb70GiCTNKM8ZqP.jpg?" a:1, c:2
2014/03/27 14:14:04 [debug] 11116#12652: *766 http special response: 404, "\upload_folder\Z5lvSRzMLxjNZZx6xJb70GiCTNKM8ZqP.jpg?"
2014/03/27 14:14:04 [debug] 11116#12652: *766 HTTP/1.1 404 Not Found