网站首页 > 精选教程 正文
nginx 的try_files $uri $uri/ xxxxx用法
如果对运维课程感兴趣,可以在b站上搜索我的账号: 运维实战课程,可以关注我,学习更多免费的运维实战技术视频
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
用章生产环境配置案例:
…
location / {
root registry/static_root;
index index.html index.htm;
}
location /ElectronicSealManagement/ {
root registry/static_root;
index index.html index.htm;
try_files $uri $uri/ /ElectronicSealManagement/index.html;
}
…
# ls /home/essapp/nginx/registry/static_root/ElectronicSealManagement/
index.html serverConfig.json static
访问: http://59.198.247.62:10004/ElectronicSealManagement/seal
如果不配置上面的,上面虽然能登录,但是如果点击刷新页面,因为访问的地址中增加了/seal,匹配不到前端地址的目录,就会报404错误,当配置上上面配置后,如果匹配不到相应的地址目录,会让其跳转到首页:ElectronicSealManagement/index.html,
因为本身处于登录状态,代码也是相对应的,只要登录不超时,刷新页面就不会变化。
如果对运维课程感兴趣,可以在b站上搜索我的账号: 运维实战课程,可以关注我,学习更多免费的运维实战技术视频
猜你喜欢
- 2024-10-12 ELK总结—第三篇Logstash监控Nginx日志存入redis,实现服务解耦
- 2024-10-12 如何对Kubernetes中的Ingress-NGINX进行监控和预警
- 2024-10-12 Nginx 动态配置 HTTP Basic Authentication 并实时推送到钉钉
- 2024-10-12 猪八戒网Nginx的动态服务发现演进之路
- 2024-10-12 Nginx+Lua+Redis实现高性能缓存数据读取
- 2024-10-12 nginx-2:部署生产级openresty nginx 部署django
- 2024-10-12 HTML5(三)——Web 本地存储 h5的本地存储是什么
- 2024-10-12 现代配置指南——YAML 比 JSON 高级在哪
- 2024-10-12 nginx输出json日志 nginx输出变量
你 发表评论:
欢迎- 最近发表
- 标签列表
-
- nginx反向代理 (57)
- nginx日志 (56)
- nginx限制ip访问 (62)
- mac安装nginx (55)
- java和mysql (59)
- java中final (62)
- win10安装java (72)
- java启动参数 (64)
- java链表反转 (64)
- 字符串反转java (72)
- java逻辑运算符 (59)
- java 请求url (65)
- java信号量 (57)
- java定义枚举 (59)
- java字符串压缩 (56)
- java中的反射 (59)
- java 三维数组 (55)
- java插入排序 (68)
- java线程的状态 (62)
- java异步调用 (55)
- java中的异常处理 (62)
- java锁机制 (54)
- java静态内部类 (55)
- java怎么添加图片 (60)
- java 权限框架 (55)
本文暂时没有评论,来添加一个吧(●'◡'●)