小编hch*_*ung的帖子

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

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

location /admin/ {
   allow 192.168.0.0/24;
   deny all;
}
Run Code Online (Sandbox Code Playgroud)

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

location ~ /admin/.*$ {
       allow 192.168.0.0/24;
       deny all;
}
Run Code Online (Sandbox Code Playgroud)

这似乎可以在从公共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;
}
Run Code Online (Sandbox Code Playgroud)

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

php nginx

9
推荐指数
2
解决办法
7826
查看次数

标签 统计

nginx ×1

php ×1