apache禁止访问网站目录
2015-08-24 20:17
841 查看
在PHP网站开发中,基于WEB服务器和PHP网站程序代码的安全考虑,我们需要对相关的目录或者文件访问权限进行控制,以防止意外情况的发生,那么我们如何来实现这种功能呢?我们可以通过Apache来实现禁止目录访问(禁止游览列出的目录或文件列表)、禁止或允许IP与域名访问目录的功能。
以下给出两种方法:
方法一:
访问网站目录时Apache默认配置为可列出目录/文件列表,即当你访问http://localhost/mysite/时会列出相关的目录和文件列表,我们可以通过修改Apache配置文件httpd.conf来实现禁止列出目录/文件列表,方法如下:
1、打开apache配置文件httpd.conf
2、找到
只需要修改Options Indexes为Options None即可,注:根据PHP运行环境安装包的不同,Options Indexes也有可能是Options IndexesFollowSymLinks,一并改为Options None即可。
还需注意的事:如果是自己重新设置了DocumentRoot,例如以下:修改的地方也就不同了
要将Options Indexes FollowSymLinks MultiViews ExecCGI改为Options FollowSymLinks MultiViews ExecCGI。即:去掉Indexs。
3、保存httpd.conf,并重启Apache即可,此时再访问http://localhost/mysite/时, 报apache http403 禁止访问错误信息
Apache/2.2.8 (Win32) PHP/5.2.6 Server at localhost Port 80
方法二:
另一种方法是在指定的web目录下的每个文件夹里面建立空的index.html或index.php文件,这样一进入相应的文件,页面会显示相应的index.php或html内容,也可解决访问目录问题,但没有解决根本问题。
至此,通过配置Apache服务器我们可以实现禁止目录访问(列出目录或文件列表),这些功能对提高和优化WEB服务器的安全性能是必不可少的方法。
参考:http://blog.sina.com.cn/s/blog_505dd27f0100orae.html
以下给出两种方法:
方法一:
访问网站目录时Apache默认配置为可列出目录/文件列表,即当你访问http://localhost/mysite/时会列出相关的目录和文件列表,我们可以通过修改Apache配置文件httpd.conf来实现禁止列出目录/文件列表,方法如下:
1、打开apache配置文件httpd.conf
2、找到
<Directory /> #Options FollowSymLinks ExecCGI Indexes Options None AllowOverride All Order deny,allow Deny from all Satisfy all </Directory>
只需要修改Options Indexes为Options None即可,注:根据PHP运行环境安装包的不同,Options Indexes也有可能是Options IndexesFollowSymLinks,一并改为Options None即可。
还需注意的事:如果是自己重新设置了DocumentRoot,例如以下:修改的地方也就不同了
<Directory "E:/AppServ/www"> # # Possible values for the Options directive are "None", "All", # or any combination of: # Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews # # Note that "MultiViews" must be named *explicitly* --- "Options All" # doesn't give it to you. # # The Options directive is both complicated and important. Please see # http://httpd.apache.org/docs/2.2/mod/core.html#options # for more information. # #Options Indexes FollowSymLinks MultiViews ExecCGI Options FollowSymLinks MultiViews ExecCGI # # AllowOverride controls what directives may be placed in .htaccess files. # It can be "All", "None", or any combination of the keywords: # Options FileInfo AuthConfig Limit # AllowOverride All # # Controls who can get stuff from this server. # Order allow,deny Allow from all </Directory>
要将Options Indexes FollowSymLinks MultiViews ExecCGI改为Options FollowSymLinks MultiViews ExecCGI。即:去掉Indexs。
3、保存httpd.conf,并重启Apache即可,此时再访问http://localhost/mysite/时, 报apache http403 禁止访问错误信息
Forbidden
You don't have permission to access /mysite/DFmeeting/resource/on this server.Apache/2.2.8 (Win32) PHP/5.2.6 Server at localhost Port 80
方法二:
另一种方法是在指定的web目录下的每个文件夹里面建立空的index.html或index.php文件,这样一进入相应的文件,页面会显示相应的index.php或html内容,也可解决访问目录问题,但没有解决根本问题。
至此,通过配置Apache服务器我们可以实现禁止目录访问(列出目录或文件列表),这些功能对提高和优化WEB服务器的安全性能是必不可少的方法。
参考:http://blog.sina.com.cn/s/blog_505dd27f0100orae.html
相关文章推荐
- 用 Apache 和 Subversion 搭建安全的版本控制环境
- Apache 防DDOS***
- centos下svn和Apache的结合使用
- 【转】【百度】 linux下单独编译安装Apache rewrite_module
- 运行apache shiro自带的samples时toolchain问题
- Apache shutdown unexpectedly启动错误解决方法
- Apache配置域名跳转、日志切割、静态缓存、防盗链
- Apache和php的关系
- Linux,Apache,PHP,mysql常用版本信息查看命令
- WampServer中Apache使用FastCGI模式跑PHP5.3nts版
- 使用apache JMeter进行web服务器的性能/压力/负载测试
- Set Apache Password Protected Directories With .htaccess File
- windows下安装Apache 64bit
- Weblogic加Apache的群集配置
- W7,64位,Apache24目录,安装php的curl扩展
- Apache POI组件操作Excel,制作报表(二)
- Apache POI组件操作Excel,制作报表(一)
- linux下 安装apache ,php等问题
- org.apache.taglibs.standard.tlv.JstlBaseTLV.validate
- openssl apache2 config