默認apache在當前目錄下沒有index.html入口就會顯示目錄,讓目錄暴露在外面是非常危險的事,如下操作禁止apache顯示目錄,希望文章對各位有幫助.
進入apache的配置文件 httpd.conf 找到如下代碼:
Options Indexes FollowSymLinks 修改為:Options FollowSymLinks
其實就是將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>
配置示例,代碼如下:
- <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>
- //開源代碼Vevb.com
建議默認情況下,設置APACHE禁止用戶瀏覽目錄內容.
新聞熱點
疑難解答