惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

WordPress大学
WordPress大学
Microsoft Security Blog
Microsoft Security Blog
Security Archives - TechRepublic
Security Archives - TechRepublic
V
Visual Studio Blog
宝玉的分享
宝玉的分享
IT之家
IT之家
人人都是产品经理
人人都是产品经理
T
The Blog of Author Tim Ferriss
I
InfoQ
B
Blog RSS Feed
T
Threatpost
博客园_首页
M
MIT News - Artificial intelligence
Spread Privacy
Spread Privacy
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Know Your Adversary
Know Your Adversary
U
Unit 42
Engineering at Meta
Engineering at Meta
C
Cyber Attacks, Cyber Crime and Cyber Security
月光博客
月光博客
Scott Helme
Scott Helme
T
Tor Project blog
有赞技术团队
有赞技术团队
AWS News Blog
AWS News Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Last Week in AI
Last Week in AI
S
Schneier on Security
Vercel News
Vercel News
博客园 - Franky
C
Cybersecurity and Infrastructure Security Agency CISA
L
LINUX DO - 热门话题
NISL@THU
NISL@THU
L
LangChain Blog
爱范儿
爱范儿
Google DeepMind News
Google DeepMind News
The GitHub Blog
The GitHub Blog
雷峰网
雷峰网
Latest news
Latest news
C
CXSECURITY Database RSS Feed - CXSecurity.com
Hugging Face - Blog
Hugging Face - Blog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
www.infosecurity-magazine.com
www.infosecurity-magazine.com
G
GRAHAM CLULEY
S
Security Affairs
A
About on SuperTechFans
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
大猫的无限游戏
大猫的无限游戏
W
WeLiveSecurity
Cisco Talos Blog
Cisco Talos Blog
罗磊的独立博客

博客园 - 遥望星空

git submodule修改url生效 最简单方式解决AppImage程序无法运行[sandbox问题] RemoteFX vGPU的尴尬现状和解决方案 DB2 8.2 9.1 9.5 9.7 下载地址(用迅雷防止官方下线文件) 远程桌面提示:身份验证错误 要求的函数不受支持 用户中心 - 博客园 java中过滤器(Filter)与拦截器(Interceptor )区别 WIN7 + IIS7 Service Unavailable HTTP Error 503. The service is unavailable. Redis中删除过期Key的三种策略 用户中心 - 博客园 在 iOS 中信任手动安装的证书描述文件 fiddler抓取手机上https数据失败,全部显示“Tunnel to......443”解决办法 搜狗拼音输入法 V9.1.0.2589 最新去广告精简优化版 安装bootcamp时提示“找不到$winpedriver$文件夹,请验证该文件夹是否和bootcamp处于同一文件夹内?” Caused by: java.security.InvalidKeyException: Illegal key size or default parameters 如何修改maven的默认jdk版本 Win10注册表无法保存对权限所作的更改拒绝访问 Win8.1/win10安装photoshop软件提示please uninstall and reinstall the product如何解决 前端页面适配的rem换算
Nginx中的rewrite指令(break,last,redirect,permanent)
遥望星空 · 2019-07-11 · via 博客园 - 遥望星空

转载自:Nginx中的rewrite指令(break,last,redirect,permanent)

rewite

在server块下,会优先执行rewrite部分,然后才会去匹配location块 server中的rewrite break和last没什么区别,都会去匹配location,所以没必要用last再发起新的请求,可以留空

location中的rewirte:

不写last和break -    那么流程就是依次执行这些rewrite 1. rewrite break -        url重写后,直接使用当前资源,不再执行location里余下的语句,完成本次请求,地址栏url不变 2. rewrite last -        url重写后,马上发起一个新的请求,再次进入server块,重试location匹配,超过10次匹配不到报500错误,地址栏url不变 3. rewrite redirect –    返回302临时重定向,地址栏显示重定向后的url,爬虫不会更新url(因为是临时) 4. rewrite permanent –    返回301永久重定向, 地址栏显示重定向后的url,爬虫更新url

使用last会对server标签重新发起请求

如果location中rewrite后是对静态资源的请求,不需要再进行其他匹配,一般要使用break或不写,直接使用当前location中的数据源,完成本次请求 如果location中rewrite后,还需要进行其他处理,如动态fastcgi请求(.php,.jsp)等,要用last继续发起新的请求 (根的location使用last比较好, 因为如果有.php等fastcgi请求还要继续处理)

使用alias指定源:必须使用last

if语句主要用来判断一些在rewrite语句中无法直接匹配的条件,比如检测文件存在与否,http header,cookie等

location匹配规则及优先级

  1. = 严格匹配这个查询。如果找到,停止搜索。
  2. ^~ 匹配路径的前缀,如果找到,停止搜索。
  3. ~ 为区分大小写的正则匹配
  4. ~* 为不区分大小写匹配 优先级: =, ^~, ~/~*, 无

break语句

放在server块rewrite语句前面 如果是直接请求某个真实存在的文件,则用break语句停止rewrite检查 if (-f $request_filename) { break; }