php – Nginx:拒绝访问其中的目录和文件

前端之家收集整理的这篇文章主要介绍了php – Nginx:拒绝访问其中的目录和文件前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我有一个目录/管理员,我想阻止目录和目录内的文件访问任何人通过公共IP访问.这是我的设置:

location /admin/ {
   allow 192.168.0.0/24;
   deny all;
}

这在访问目录时工作正常,但是,如果有人专门访问目录中的文件(例如,url =“../ admin / adminer.PHP),它不会拒绝访问该文件.我也尝试过其他设置如:

location ~ /admin/.*${
       allow 192.168.0.0/24;
       deny all;
}

这似乎可以在从公共IP访问时拒绝所有访问,当通过内部IP访问时,PHP代码不再有效,PHP代码只是以明文形式回显.

这里提供了我的其他位置指令,以防它以某种方式影响行为:

location / {
   try_files $uri $uri/ /index.PHP?args;
}
location ~ \.PHP${
  include snippets/fastcgi-PHP.conf;
  fastcgi_pass unix:/var/run/PHP5-fpm.sock;
  fastcgi_split_path_info ^(.+\.PHP)(/.+)$;

  fastcgi_cache_bypass $skip_cache;
  fastcgi_no_cache $skip_cache;
  fastcgi_cache wordpress;
  fastcgi_cache_valid 60m;
}

希望有人能帮助我解决这个问题.

最佳答案
创建另一个位置块,看看它是否有效:

    location ~ /admin/.*\.PHP${
       allow 192.168.0.0/24;
       deny all;

       include snippets/fastcgi-PHP.conf;
       fastcgi_pass unix:/var/run/PHP5-fpm.sock;
       fastcgi_split_path_info ^(.+\.PHP)(/.+)$;

       fastcgi_cache_bypass $skip_cache;
       fastcgi_no_cache $skip_cache;
       fastcgi_cache wordpress;
       fastcgi_cache_valid 60m;
    }
原文链接:https://www.f2er.com/nginx/434486.html

猜你在找的Nginx相关文章