nginx 的try_files $uri $uri/ xxxxx用法

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

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

运维实战帮

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值