如何使Nginx停止处理其他规则并服务于特定位置? [英] How to make nginx to stop processing other rules and serve a specific location?
问题描述
我有这个配置,可以在空的server { }
定义中正常工作
I have this config that works as expected in an empty server { }
definition
location ^~ /foo/ {
alias /var/www/foo/;
}
但是,当我在一个更大的服务器定义(用于WordPress多站点配置的服务器定义)中移动它时,它将停止工作,而wordpress会对此做出响应(这显然不是我的意图).
But when I move this in a considerably bigger server definition (one used for a WordPress multi-site config), it will stop working and wordpress will respond to it (which obviously was not my intent).
我试图放在服务器块的开头或结尾,但这并没有改变.
I tried to put at the begining or end of server block, but this didn't change it.
如何强制Nginx使用此位置?
How can I force Nginx to use this location?
推荐答案
您可能正在寻找break
.
location ^~ /foo/ {
alias /var/www/foo/;
break;
}
last
-完成当前重写指令的处理,并 通过搜索匹配项重新启动过程(包括重写) 在所有可用位置的URI上显示.
last
- completes processing of current rewrite directives and restarts the process (including rewriting) with a search for a match on the URI from all available locations.
break
-完成当前重写指令的处理,并
非重写处理在当前位置块内继续
break
- completes processing of current rewrite directives and
non-rewrite processing continues within the current location block
only.
请注意,外部位置障碍,过去和休息实际上是 一样.
Note that outside location blocks, last and break are effectively the same.
这篇关于如何使Nginx停止处理其他规则并服务于特定位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!