nginx中的location以及rewrite

常见的Nginx正则表达式

在这里插入图片描述

location

location种类

精准匹配:location = / {}
一般匹配:location / {}
正则匹配:location ~ / {}

location常用的匹配规则

在这里插入图片描述

location 优先级

在这里插入图片描述

location 示例说明:

location = / {}

在这里插入图片描述

location / {}

在这里插入图片描述

location /documents/ {}

在这里插入图片描述

location /documents/abc {}

在这里插入图片描述

location ^~ /images/ {}

在这里插入图片描述

location ~* .(gif|jpg|jpeg)$ {}

在这里插入图片描述

location /images/abc {}

在这里插入图片描述

location ~ /images/abc {}

在这里插入图片描述

location /images/abc/1.html {}

在这里插入图片描述

优先级

(location =) > (location 完整路径) > (location ^~ 路径) > (location ,* 正则顺序) > (location 部分起始路径) > (location /)

实际网站使用中,至少有三个匹配规则定义

在这里插入图片描述
在这里插入图片描述

rewrite

在这里插入图片描述

rewrite 跳转实现

在这里插入图片描述

rewrite执行顺序

执行server块里面的rewrite指令

执行location匹配

执行选定的location中的rewrite指令

rewrite语法格式

在这里插入图片描述

flag标记说明

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值