Nginx错误
0
首先我们来解决last
和break
的区别:
root html;
index index.html;
location /c/ {
rewrite .* /;
}
location /a/ {
rewrite .* /c/ last;
}
location /b/ {
rewrite .* /c/ break;
}
访问localhost/a/
时访问的是html/index.html
访问localhost/b/
时访问的是html/c/index.html
好了,然后我们修改配置:
location /a/ {
rewrite .* /a/ last;
}
这种情况访问时,系统提示500
错误,错误日志:
rewrite or internal redirection cycle while processing "/a/", client: 127.0.0.1, server: localhost, request: "GET /a/ HTTP/1.1", host: "localhost"
那么下面这个情况呢:
location /b/ {
rewrite .* /b/ break;
}
这个情况就比较复杂了
第一种情况:路径html/b/
不存在时,提示404
"D:\Program Files (x86)\nginx-1.4.7/html/b/index.html" is not found (3: The system cannot find the path specified), client: 127.0.0.1, server: localhost, request: "GET /b/ HTTP/1.1", host: "localhost"
第二种情况:路径html/b/
存在,但是没有index.html
时,提示403
directory index of "D:\Program Files (x86)\nginx-1.4.7/html/b/" is forbidden, client: 127.0.0.1, server: localhost, request: "GET /b/ HTTP/1.1", host: "localhost"
第三种情况:路径和文件都存在时,能不能访问呢?答案是不能,提示500
rewrite or internal redirection cycle while internally redirecting to "/b/index.html", client: 127.0.0.1, server: localhost, request: "GET /b/ HTTP/1.1", host: "localhost"
搞的我也有点懵了。而且使用了break
也会匹配到其他location
,难道是Windows的问题。