Apache默認在當前目錄下沒有index.html入口就會顯示網站根目錄,讓網站目錄文件都暴露在外面,是一件非常危險的事,例如:數據庫密碼洩露,隱藏頁面暴露等嚴重安全問題!
例如,訪問米撲網站根目錄: https://mimvp.com 會列出根目錄
本文將詳細介紹如何操作禁止顯示apache網站根目錄
進入apache的配置文件 httpd.conf 找到:
vim /etc/httpd/conf/httpd.conf
Options Indexes FollowSymLinks
修改為:
Options FollowSymLinks
修改後結果如下:
# Options None
# Options Indexes FollowSymLinks
Options FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
其實就是將Indexes去掉,Indexes表示若當前目錄沒有index.html就會顯示目錄結構。
重啟Apache服務器 /etc/init.d/httpd restart
再訪問米撲網站,就沒問題了: https://mimvp.com
1. 禁止訪問某些文件/目錄
增加Files選項來控制,比如要不允許訪問 .inc 擴展名的文件,保護php類庫:
Order allow,deny
Deny from all
禁止訪問某些指定的目錄:(可以用
Order allow,deny
Deny from all
通過文件匹配來進行禁止,比如禁止所有針對圖片的訪問:
Order allow,deny
Deny from all
針對URL相對路徑的禁止訪問:
Order allow,deny
Deny from all
配置示例
#
# 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
建議默認情況下,設置APACHE禁止用戶浏覽目錄內容。