363人参与 • 2024-09-17 • Powershell
如果return指令
跟rewrite指令
同时存在先执行哪个呢?
server { location /images { rewrite /images/(.*)$ /pic/$1 last; return 200 "return 200 in /images"; } location /pic { rewrite /pic/(.*) /photos/$1; return 200 "return 200 in /pic"; } location /photos { return 200 "return 200 in /photos"; } }
分别在/images
、/pic
、/photos
的location段增加return 返回200状态码并输出字符串
xxx.com/images/index.html
,会进入/images的location段中
,/images
中,进行rewrite指令
,将images/index.html重写到/pic/
的index.html,并且有last 值
。last值
,会重新触发请求。在server段
找/pic
的location段。/pic
后 ,又重写,将/pic
的index.html重定向到/photos
目录下的index.html。(注意/pic段没有加last值,意味着流程顺序执行!)/pic段
中依然执行下面的命令,会走retrun 200 "return 200 in /pic"
之后就中断。如果在/pic段中
增加flag的break
,会执行什么?
当遇到break
,会重写找/photos段
,不会执行return 200 in /pic
,
如果当你直接访问xxx.com/photos/index.html
, 但是又有return指令
, 会优先执行return指令 , 并不会返回photos/index.html
的页面,直接返回return结果给你。
如果没有return指令
才会找目录对应下的有没有index.html
文件。
到此这篇关于nginx中return和rewrite指令同时存在先执行顺序哪个的文章就介绍到这了,更多相关nginx中return和rewrite指令执行顺序内容请搜索代码网以前的文章或继续浏览下面的相关文章希望大家以后多多支持代码网!
您想发表意见!!点此发布评论
版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。
发表评论