加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 运营中心 > Nginx > 正文

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

发布时间:2020-12-13 21:32:34 所属栏目:Nginx 来源:网络整理
导读:我有一个目录/管理员,我想阻止目录和目录内的文件访问任何人通过公共IP访问.这是我的设置: location /admin/ { allow 192.168.0.0/24; deny all;} 这在访问目录时工作正常,但是,如果有人专门访问目录中的文件(例如,url =“../ admin / adminer.php),它不会

我有一个目录/管理员,我想阻止目录和目录内的文件访问任何人通过公共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;
    }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读