网站首页 > 技术教程 正文
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-11 405状态码Nginx解决办法(nginx 405错误)
- 2024-09-21 nginx五大核心功能全解析 #干货#高并发
- 2024-09-21 Nginx基础入门006(nginx最全教程)
- 2024-09-21 详解 nginx负载均衡原理(nginx负载均衡的5种策略及原理)
- 2024-09-21 nginx入门——web服务器(四)(nginx web服务器)
- 2024-09-21 Nginx缓存(nginx缓存静态文件)
- 2024-09-21 Nginx基础入门003(nginx 教程)
- 2024-09-21 Nginx配置$request_uri与$uri变量的区别
- 2024-09-21 在 Nginx 中如何将$request_uri作为单独的参数传递
你 发表评论:
欢迎- 最近发表
-
- Win10 TH2正式版官方ESD映像转换ISO镜像方法详解
- 使用iso镜像升级到Windows 10的步骤
- macOS Ventura 13.2 (22D49) Boot ISO 原版可引导镜像
- 安利一个用ISO镜像文件制作引导U盘的的小工具RUFUS
- CentOS 7使用ISO镜像配置本地yum源
- 用于x86平台的安卓9.0 ISO镜像发布下载:通吃I/A/N、完全免费
- AlmaLinux 9.6发布:升级工具、初步支持IBM Power虚拟化技术
- Rufus写入工具简洁介绍与教程(写入模式)
- 新硬件也能安装使用了,Edge版Linux Mint 21.3镜像发布
- 开源工程师:Ubuntu应该抛弃32位ISO镜像
- 标签列表
-
- 下划线是什么 (87)
- 精美网站 (58)
- qq登录界面 (90)
- nginx 命令 (82)
- nginx .http (73)
- nginx lua (70)
- nginx 重定向 (68)
- Nginx超时 (65)
- nginx 监控 (57)
- odbc (59)
- rar密码破解工具 (62)
- annotation (71)
- 红黑树 (57)
- 智力题 (62)
- php空间申请 (61)
- 按键精灵 注册码 (69)
- 软件测试报告 (59)
- ntcreatefile (64)
- 闪动文字 (56)
- guid (66)
- abap (63)
- mpeg 2 (65)
- column (63)
- dreamweaver教程 (57)
- excel行列转换 (56)
本文暂时没有评论,来添加一个吧(●'◡'●)