apache的文件列表是怎么实现的

apache的文件列表是怎么实现的,第1张

1、进入apache的配置文件 httpd.conf 找到:

代码如下

Options Indexes FollowSymLinks

修改为:

Options FollowSymLinks

2、其实就是将Indexes去掉,Indexes表示若当前目录没有index.html就会显示目录结构。

代码如下

1. 禁止访问某些文件/目录

增加Files选项来控制,比如要不允许访问 .inc 扩展名的文件,保护php类库:

<Files ~ ".inc$">

Order allow,deny

Deny from all

</Files>

禁止访问某些指定的目录:(可以用 <DirectoryMatch> 来进行正则匹配)

<Directory ~ "^/var/www/(.+/)*[0-9]{3}">

Order allow,deny

Deny from all

</Directory>

通过文件匹配来进行禁止,比如禁止所有针对图片的访问:

<FilesMatch .(?i:gif|jpe?g|png)$>

Order allow,deny

Deny from all

</FilesMatch>

针对URL相对路径的禁止访问:

<Location /dir/>

Order allow,deny

Deny from all

</Location>

3、配置示例:

代码如下

<Directory "E:/Program Files/Apache Software Foundation/Apache2.2/htdocs">

#

# 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.

# 就是这一行,只去掉indexes也可

#Options Indexes FollowSymLinks

Options FollowSymLinks

#

# 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 None

#

# Controls who can get stuff from this server.

#

Order allow,deny

Allow from all

</Directory>

打开httpd.conf ,将配置文件里的

Options Indexes FollowSymLinks

改成

Options FollowSymLinks

这样就不会显示文件列表了。记得需要重启apache服务

屏蔽网站htdocs文件目录,将$apache_home/conf/httpd.conf文件以下项注释掉

#DocumentRoot "/opt/IBM/HTTPServer/htdocs"

#<Directory "/opt/IBM/HTTPServer/htdocs">

#    Options FollowSymLinks

#    AllowOverride None

#    Order allow,deny

#    Allow from all

#</Directory>


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/tougao/11540475.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-16
下一篇2023-05-16

发表评论

登录后才能评论

评论列表(0条)

    保存