找回密码
 注册
首页 ≡≡网络技术≡≡ 服务器 在apache中添加多个虚拟主机(虚拟目录)的方法 ...

在apache中添加多个虚拟主机(虚拟目录)的方法

灰儿 2008-9-23 11:23:48
方法一:
在httpd.conf 里找到类似
# Virtual hosts
#Include conf/extra/httpd-vhosts.conf
=>
# Virtual hosts
   Include conf/extra/httpd-vhosts.conf

然后在 conf/extra/目录下找到 httpd-vhosts.conf修改配置:

<VirtualHost *>
    DocumentRoot ../htdocs
    ServerName defalut:80
    ErrorLog logs/defalut-error_log
</VirtualHost>

<VirtualHost *>
    ServerAdmin admin@www.sq01.cn
    DocumentRoot d:/web
    ServerName www.sq01.cn:80
    ServerAlias www.sq01.cn
    ErrorLog logs/www.sq01.cn-error_log
</VirtualHost>

方法二:
直接在 httpd.conf 中添加:
打开Apache的conf文件httpd.conf,找到“#NameVirtualHost *:80”这一行(这一行在文件的最后面倒数二十多行的位置上,可以用搜索)。把前面的#去掉。在conf文件中的任意位置(建议在最下面),添加新增虚拟主机的代码:

  <VirtualHost *:80>
  DirectoryIndex default.php
  ServerName "www.host1.com"
  DocumentRoot "D:/wwwroot/host1/"
  ErrorLog "H:/log/host1.log"
  TransferLog "H:/log/host1access.log"
  </VirtualHost>
  <VirtualHost *:80>
  DirectoryIndex default.php
  ServerName "www.host2.com"
  DocumentRoot "E:/wwwroot/host2/"
  ErrorLog "H:/log/host2.log"
  TransferLog "H:/log/host2access.log"
  </VirtualHost>

以上是添加了两个域名,分别指向两个目录。大家一看这个格式就能看懂,因此不再赘述。
另外,在serverName中还可以使用通配符*。如 *.sq01.cn表示任意的sq01.cn的二级域名。

个人感觉如果需要多个虚拟主机的话,还是使用第一种方法便于管理些,另外再提醒一下,每次修改完apache的conf文件后都要重启apache才能生效。

[ 本帖最后由 灰儿 于 2008-9-24 11:51 编辑 ]
您需要登录后才可以回帖 登录 | 注册
学习中心
站长自定义文字内容,利用碎片时间,随时随地获取优质内容。
Q设计语言 了解更多
Q Design 提供商家设计所需的指导与资源,帮商家快速完成产品设计、降低生产成本。
学习中心
站长自定义文字内容,利用碎片时间,随时随地获取优质内容。
Q设计语言 了解更多
Q Design 提供商家设计所需的指导与资源,帮商家快速完成产品设计、降低生产成本。