关于apache服务器的虚拟目录和虚拟主机的设置

来源:互联网 发布:与程序员算法有关的书 编辑:程序博客网 时间:2024/05/16 11:54

虚拟目录:apache服务器默认有一个默认目录为htdocs,站点默认放在这个目录下。当在浏览器输入网址时,默认查找的是这个地址。如果想要更改默认访问目录,就需要设置虚拟目录。

虚拟主机:每次访问站点的时候需要在ip地址后面加上站点名 例如:localhost/mysite。如何把它改成像www.sohu.com那样的,不用再后面多余的添加站点名。就需要设置虚拟主机。


虚拟目录设置步骤如下:

1、在httpd.config中禁用默认的站点目录

#DocumentRoot "D:/Apache2.2.25/htdocs"

2、在httpd.config的<IfModule dir_module>  DirectoryIndex index.html </IfModule>后面添加

<IfModule dir_module>
   #direcotory相当于是欢迎页面
  DirectoryIndex news.html index.html index.htm index.php
    #你的站点别名
   Alias /myblog "f:/myblog"
   <Directory f:/myblog>
   #这是访问权限设置
  Order allow,deny
   Allow from all
   </Directory>
</IfModule>

3、保证f:/myblog真实存在


这个时候站点目录就从"D:/Apache2.2.25/htdocs" 更改到"f:/myblog"


当访问资源的时候就会去"f:/myblog"中查找


虚拟主机设置步骤如下:

1、在httpd.config中启用虚拟主机文件

# Virtual hosts
Include conf/extra/httpd-vhosts.conf

2、在httpd-vhosts.conf中进行虚拟主机的设置

#配置我们自己的虚拟主机
<VirtualHost 127.0.0.1:81>
    DocumentRoot "e:/myblog"
    #这里配置欢迎首页面 
    DirectoryIndex news.html index.html index.htm index.php
    <Directory />
    Options FollowSymLinks
    #不许可别人修改我们的页面
    AllowOverride None
    #设置访问权限
    Order allow,deny
    Allow from all
    </Directory>
</VirtualHost>


当访问localhost:81的时候会直接定位到e:/myblog。例如文件夹中的xxx.html,可以这样访问 localhost:81/xxx.html。不需要再想以前localhost:81/myblog/xxx.html




0 0
原创粉丝点击