Nginx location具有如下配置,如果在客户端输入localhost/app1,最后访问的路径为
/etc/nginx/html/common/app1/index,而没有访问/etc/nginx/html/index.html。
分析原因如下:
(1)nginx首先匹配/app1/,由于没有指定页面,会使用配置的index.html,即访问的URI变为/app1/index.html,
(2)此时,由于可以精确匹配/app1/index.html,会导致最后访问的是 /etc/nginx/html/common/app1/index。
location /app1/ {
root /etc/nginx/html;
index index.html;
}
location /app2/ {
root /etc/nginx/html;
index home.html;
}
location / {
root /etc/nginx/html/common;
index index.html;
}
location = /app1/index.html {
root /etc/nginx/html/common;
}
监控访问到的日志如下:
172.17.0.1 - - [27/Nov/2019:10:29:54 +0000] "/etc/nginx/html/common/app1/index.html" "GET /app1/ HTTP/1.1" 404 570 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36" "-"