位置指令在nginx中仅用于root,嵌套在/

我有一个proxy_pass工作/,并希望某些configuration只适用于根。

我试过了

location / { proxy_pass http://foo.com/ } location = / { subs_filter 'foo' 'bar'; } 

但我从foo.com得到404 – 我将如何使subs_filter只适用于根?

对于nginx,只使用“该”一个匹配位置块; 在这个问题中,这意味着对于url /没有proxy_pass – 它会将请求视为对(在默认情况下,如果未configuration)根目录中的文件的请求。

文档中有一个非常类似于这个问题的例子:

 location /user/ { proxy_pass http://user.example.com; } location = /user { proxy_pass http://login.example.com; } 

应用这个问题唯一缺less的是将proxy_pass添加到= /位置块,即

 location / { proxy_pass http://foo.com/ } location = / { proxy_pass http://foo.com/ subs_filter 'foo' 'bar'; }