nginx通过ip限制目录访问

我正在使用Nginx,并希望限制除了我自己以外的所有人访问目录.我想访问/限制的PHP脚本.到目前为止我已经尝试了一些东西.如果我记得,除了允许的ip之外,这可以阻止对所有脚本的访问,但所有脚本都被推送下载而不是现在处理.

location~ / restricted {
  允许1.2.3.4;
  否认所有;
}

你需要第二个(我更喜欢嵌套)PHP块,因为你希望这些PHP文件的处理方式不同.此外,假设/ restricted应该是uri前缀,而不仅仅是出现在uri中的任何位置,您需要一个不同类型的位置:

# This handles everything that starts with /restricted,# and no regex locations will override it
location ^~ /restricted {
  allow 1.2.3.4;
  deny all;

  # This will inherit the allow/deny from the outer location
  location ~ \.PHP${
    include fastcgi.conf;
    fastcgi_pass backend;
  }
}

相关文章

Nginx (engine x) 是一个高性能的HTTP和反向代理服务,也是一...
本地项目配置 1 复制 luffy/settings/dev.py为prop.py 修改l...
nginx不仅可以隐藏版本信息,还支持自定义web服务器信息 先看...
一 、此次漏洞分析 1 nginx HTTP/2漏洞 [nginx-announce] ng...
###进入nginx 目录cd /usr/local/nginx###递归显示 2 级目录...
在cmd命令窗口输入下面命令进行查看 tasklist /fi "ima...