apache有没有办法限制一个项目中某几个目录的PHP文件可以被访问,其它PHP文件都不能被访问。


apache有没有办法限制一个项目中某几个目录的PHP文件可以被访问,其它PHP文件都不能被访问。

问题看似简单,但是我想破头也找不出解决方法。

谷歌什么的 我都搜了。求解。

apache2.2 apache 网络安全 php 服务器

Kurum1_ 10 years, 8 months ago

你据说的【可以被访问】是什么意思,浏览器端可以通过http访问吗?

例如,www/html, www/pub, www/private三个目录,只有 http://test.com/html , http://test.com/pub 可以访问,访问 http://test.com/private 时报403 Forbidden错误。

如果是这个需求,apache是可以做到的:


 <Directory /docroot/www/private>
    Order Deny,Allow
    Deny from all
</Directory>

详情参见: http://httpd.apache.org/docs/current/mod/mod_access_compat.html

Apache安装好之后,自带的httpd.conf里也有这样的示例配置。

如果你说的访问是指【PHP include】,比如www/index.php,可以include www/html, www/pub两个目录的文件,但include www/private下的文件时,报permission denied,那你只要把www/private的权限设成766,并让apache进程的owner不是www/private目录的owner即可

爆钓王希卡利 answered 10 years, 8 months ago

Your Answer