我有一个目录/管理员,我想阻止目录和目录内的文件访问任何人通过公共IP访问.这是我的设置:
@H_404_6@location /admin/ { allow 192.168.0.0/24; deny all; }
这在访问目录时工作正常,但是,如果有人专门访问目录中的文件(例如,url =“../ admin / adminer.PHP),它不会拒绝访问该文件.我也尝试过其他设置如:
@H_404_6@location ~ /admin/.*${ allow 192.168.0.0/24; deny all; }
这似乎可以在从公共IP访问时拒绝所有访问,当通过内部IP访问时,PHP代码不再有效,PHP代码只是以明文形式回显.
这里提供了我的其他位置指令,以防它以某种方式影响行为:
@H_404_6@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; }
希望有人能帮助我解决这个问题.
最佳答案
创建另一个位置块,看看它是否有效:
@H_404_6@ 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; }