Nginx 位置块特定文件

Jus*_*tin 3 nginx

我有以下 nginx 位置块:

location /publish/domain.io.php {
  allow 127.0.0.1;
  deny all;
}

location ~\.php {
  try_files $uri =404;
  fastcgi_index index.php;
  fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  fastcgi_intercept_errors on;
  fastcgi_pass 127.0.0.1:9000;
  include /etc/nginx/fastcgi_params;
}
Run Code Online (Sandbox Code Playgroud)

问题是位置块/publish/domain.io.php似乎没有执行。我可以domain.io.php从任何主机调用 php 脚本。

想法?非常感谢。

Max*_*bey 5

使用=位置前缀来确定完全匹配。正如nginx 文档中所写:“如果找到完全匹配,则搜索终止。”

因此,您的位置应如下所示:

location = /publish/domain.io.php {
  允许 127.0.0.1;
  否认一切;# 给出 403
}

或者

location = /publish/domain.io.php {
  内部的; # 给出 404
}