nginx优先考虑外部位置块的嵌套位置

有人可以解释为什么这不按照人们所期望的方式工作吗? 在下面的nginxconfiguration中,假设第一个nginx将使用正则expression式匹配的图像扩展块,只有在之后才会进入内部块,其中^~优先于其他所有内容。

看起来nginx正在查看更大的图片而不考虑范围,并匹配像/images/something.png类的请求的外部正则expression式扩展块之前的^~ /images

 location ~* \.(css|js|jpg|png|gif|ico)$ { expires 7d; add_header Image-By-Extension 1; } location / { location ^~ /images { add_header Image-By-Folder 1; ... } } 

是的,nginx必须select一个位置,所以以后不会报告匹配,即使你正在嵌套它们。 当你使用~^运算符时,你告诉nginx避免查看正则expression式位置块,如果它是匹配当前请求URI的最长的前缀位置块。

我在这里解释了整个过程: Nginx rewite规则403错误 。