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;
    }

dawei

【声明】:唐山站长网内容转载自互联网,其相关言论仅代表作者个人观点绝非权威,不代表本站立场。如您发现内容存在版权问题,请提交相关链接至邮箱:bqsm@foxmail.com,我们将及时予以处理。