关于apache虚拟目录和虚拟主机区别与设置方式

一:关于apache虚拟目录alias
关 于apache虚拟目录的问题,apache的config文件中documentRoot 后面的是apache在解析页面时候的跟目录,如果在本机上同是存在两个工作目录那么如果不虚拟(alias)目录的话,需要不断修改 documentroot的路径,然后重启apache,相当麻烦,解决这个问题的办法之一就是设置虚拟目录,具体做法如下:
Alias /虚拟目录名/ "盘符:/路径/"

<Directory "盘符:/路径/">
   Options Indexes MultiViews
   AllowOverride None
   Order allow,deny
   Allow from all
</Directory>

但是虚拟目录有一个不好处是,工作目录只能放到某个盘的根目录下,比如:d:/workfolder1 , d:/workfolder2,如果不这样放,那么apache在解析根的时候就出问题了。
比如我现在的工作目录是:d:/workspace/workfolder1 , d:/workspace/folder2,那么用alias就实现不了了,如何解决呢,用apache的虚拟主机
二:虚拟主机:

具体做法是:
   NameVirtualHost *

    <VirtualHost *>
    ServerName www.domain.tld
    DocumentRoot d:/workspace/workfolder1
    </VirtualHost>

    <VirtualHost *>
    ServerName www.otherdomain.tld
    DocumentRoot d:/workspace/workfolder2
    </VirtualHost>
当然里面还有

ServerAlias
ServerPath
等参数,可以不设置,具体参考官方手册:http://httpd.apache.org/docs/2.0/vhosts/
如果是在本机上还需要解决hosts的问题,你这样虚拟之后如果host文件不做转向处理,那么是有冲突的,需要在host文件中加这两句:
127.0.0.1 www.domain.tld
127.0.0.1 www.otherdomain.tld
然后关掉浏览器,重启apache服务,ok,这样就搞定了,通过浏览器这样访问自己的工作目录就可以了
http//:www.domain.tld访问:d:/workspace/workfolder1
http://www.domain.tld访问:d:/workspace/workfolder2

设置了虚拟主机后,可以会出现"你没有访问权限"什么的 ,要修改

<Directory "D:/workspace/workfolder1">
    #
    # 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>


转自 http://hi.baidu.com/yabozicom/item/207ee685e734be2d100ef39d

 

原文地址:https://www.cnblogs.com/seesky/p/2581471.html