Nginx 位置块的行为是递归的

Jus*_*tin 2 nginx

location在 nginx 中有以下块:

location /stats {
  allow 127.0.0.1;
  deny all;
}
Run Code Online (Sandbox Code Playgroud)

如果我尝试/stats从我的家用 MacBook 上查看,我会得到403 Forbidden预期的结果。但是,如果我查看,/stats/index.php我可以查看它。我的印象是location /stats会递归地应用(即对所有孩子)。

如何使这个位置块按预期运行?

谢谢。

ghl*_*ogh 8

您需要指定位置“开始于”:

location ^~ /stats {
  allow 127.0.0.1;
  deny all;
}
Run Code Online (Sandbox Code Playgroud)