1.try_files $uri $uri/ xxxxx理解
当访问的地址中不匹配$uri(用户访问地址)和$uri/(用户访问地址/下面)时候,会跳转到定义的最后的xxxx页面
2.案例
[root@localhost ~]# cat /usr/local/nginx/conf/nginx.conf |grep vhost
include vhost/*.conf;
[root@localhost ~]# cat /usr/local/nginx/conf/vhost/www.1.conf
server{
listen 80;
server_name www.1.com;
location /abc/ {
root /data/wwwroot/www.1.com/;
index index.html;
try_files $uri $uri/ /abc/a/index.html;
#当http://www.1.com/abc 和http://www.1.com/abc/下的路径匹配不上时候,如:http://www.1.com/abc/xxxxx,跳转到最后一个:/abc/a/index.html
}
}
[root@localhost ~]# ls /data/wwwroot/www.1.com/
abc
[root@localhost ~]# tree /data/wwwroot/www.1.com/abc/
/data/wwwroot/www.1.com/abc/
├── 1.html
├── 2.html
├── a
│ ├── a.html
│ └── index.html
├── b
│ ├── b.html
│ └── index.html
└── index.html
[root@localhost ~]# cat /data/wwwroot/www.1.com/abc/1.html
111
[root@localhost ~]# cat /data/wwwroot/www.1.com/abc/2.html
222
[root@localhost ~]# cat /data/wwwroot/www.1.com/abc/index.html
abc_index
[root@localhost ~]# cat /data/wwwroot/www.1.com/abc/a/a.html
aaa
[root@localhost ~]# cat /data/wwwroot/www.1.com/abc/a/index.html
a_index
[root@localhost ~]# cat /data/wwwroot/www.1.com/abc/b/b.html
bbb
[root@localhost ~]# cat /data/wwwroot/www.1.com/abc/b/index.html
b_index
[root@localhost ~]# /usr/local/nginx/sbin/nginx -s reload
当访问地址中匹配上前面两个定义的地址时候,则进行正常的访问,如下: $uri $uri/
当访问地址中没有匹配上前面两个定义的地址时候,则进会跳转到最后定义的地址,如下: /abc/a/index.html