apache 文件目录配置

1.如果不启用vhosts

只需修改httpd.conf

默认Directory节如下,注意红色部分,表示目录/usr/local/apache/htdocs允许所有主机访问

<Directory "/usr/local/apache/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.
#
#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

</Directory>

由于主目录被指到别的地方了,所以将蓝色部分/usr/local/apache/htdocs换成你新的主目录就OK了。

2.启用vhosts
启用vhosts的话,你就可以不作上面的修改了,因为VirtualHost可以单独配置这个节的属性,所以我们在VirtualHost这个节里配置的话就更方便了,下面的配置中,我把我的网站放在/var/vhosts/www.test.cn下。

/usr/local/apache/conf/extra/httpd-vhosts.conf
<VirtualHost *:80>
<Directory "/var/vhosts/www.test.cn" >
#Deny from all
Allow from all
</Directory>

DocumentRoot "/var/vhosts/www.test.cn"
ServerName www.test.cn
</VirtualHost>

如果把Deny from all的注释去掉,那么服务器就会拒绝所有访问(和我们刚开始把主目录移动到htdocs外而没做任何配置修改时一样,哈哈)

补充一点:
如果你是写个index.php放在目录下测试,可要注意了,记得加上默认主页index.php
DirectoryIndex index.html index.php

详细语法请看:
http://www.linuxpk.com/doc/apache/mod/mod_authz_host.html
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值