后來發(fā)現(xiàn),原來又是Apache沒配置 好,是apache的mod_authz_host模塊在起控制作用。
1.如果不啟用vhosts
只需修改 httpd.conf
默認(rèn)Directory節(jié)如下,注意紅色部分,表示目錄/usr/local/apache/htdocs允許所有 主機(jī)訪問
復(fù)制代碼代碼如下:
#
# 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
#
# 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
由于主目錄被指到別的地方了,所以將藍(lán)色部分/usr/local/apache/htdocs換成你新的主目錄就OK了。
2.啟用vhosts
啟 用vhosts的話,你就可以不作上面的修改了,因?yàn)閂irtualHost可以單獨(dú)配置這個(gè)節(jié)的屬性,所以我們?cè)赩irtualHost這個(gè)節(jié)里配置的 話就更方便了,下面的配置中,我把我的網(wǎng)站放在/var/vhosts/www.test.cn下。
復(fù)制代碼代碼如下:
/usr/local/apache/conf/extra/httpd-vhosts.conf
#Deny from all
Allow from all
DocumentRoot "/var/vhosts/www.test.cn"
ServerName www.test.cn
如果把Deny from all的注釋去掉,那么服務(wù)器就會(huì)拒絕所有訪問(和我們剛開始把主目錄移動(dòng)到htdocs外而沒做任何配置修改時(shí)一樣,哈哈)
補(bǔ)充一點(diǎn):
如果你是寫個(gè)index.php放在目錄下測(cè)試,可要注意了,記得加上默認(rèn)主頁index.php
DirectoryIndex index.html index.php