0
我在我的nginx配置中想出了一个奇怪的Nginx行为。
在遵循this blog post以便能够处理多个命名地点之后,我很快意识到我正在填充我的nginx错误日志。 事实上,对于没有匹配的静态文件,我一直有一个文件系统打开错误的每个请求:[error] 11111#0: *20 open() "/www/hello/action" failed (2: No such file or directory)
这个nginx的配置:
server {
root /www/hello;
location/{
try_files /non-existent-4-ever @all;
}
location @all {
# Expecting Nginx to serve static files and return 404 for non existent files
error_page 404 = @backend;
}
location @backend {
return 200 "hello";
}
}
而这些文件:
[email protected]:/www/hello$ ls -l
total 8
-rw-r--r-- 1 root root 6 Sep 23 13:45 file1.txt
-rw-r--r-- 1 root root 6 Sep 23 13:45 file2.txt
via:
[email protected]:/www/hello$ curl localhost/file1.txt
content_file1.txt
我能顺利拿到
通过静态文件的内容:
[email protected]:/www/hello$ curl localhost/action
hello
我从@backend
顺利拿到结果(它总是返回hello
)
但我也得到一个nginx错误日志中的错误:
[email protected]:/www/hello$ tail -f /var/log/nginx/error.log
2014/09/23 13:50:13 [error] 111111#0: *19 open() "/www/hello/action" failed (2: No such file or directory), client: 172.17.42.1, server: , request: "GET /action HTTP/1.1", host: "172.17.0.2:80"
你们认为这是Nginx的错误吗?
PS:我通过如下第二命名位置添加的文件检查解决了错误日志:
location @all {
# Expecting Nginx to serve static files and return 404 for non existent files
error_page 404 = @backend;
if (!-f $request_filename) {
return 404;
}
}
干杯@Melvyn,这部分文件没有达到我的眼睛,我猜。你做出了我的好回答! – 2014-09-26 18:07:06