nginx在location中使用rewrite后会匹配其他location的规则吗我不想要使用rewrite后再匹配其他location规则要怎么处理
在nginx中,如果一个请求匹配到了某个location,那么它会按照这个location中的规则进行处理。如果在这个location中使用了rewrite,而且rewrite后的URI又匹配到了其他的location规则,那么nginx会继续按照这个新的location规则进行处理。
如果你不想让rewrite后的请求继续匹配其他location规则,可以在rewrite规则中加上last标记,例如:
location /foo {
rewrite ^/foo/(.*)$ /bar/$1 last;
...
}
location /bar {
...
}
这样,请求匹配到/foo后会被rewrite成/bar,但是由于加了last标记,nginx会停止继续匹配其他location规则,直接按照/bar的规则进行处理。
原文地址: https://www.cveoy.top/t/topic/d84w 著作权归作者所有。请勿转载和采集!