apache配置虚拟主机,为什么总是第一个VirtualHost起效

adrlanoqq 2011-11-05 03:55:42
hosts 配置如下:
/*********************************
127.0.0.1 localhost
127.0.0.1 school.jiaoyu365.net
127.0.0.1 m.jiaoyu365.net
127.0.0.1 c.jiaoyu365.net
127.0.0.1 api.app.jiaoyu365.net
/*********************************


httpd.conf配置如下
/*********************************
NameVirtualHost *:80

<VirtualHost school.jiaoyu365.net>
ServerName school.jiaoyu365.net>
ServerAdmin webmaster@localhost

DocumentRoot D:/wamp/www/school

<Directory D:/wamp/www/school>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
</VirtualHost>

<VirtualHost m.jiaoyu365.net>
ServerName m.jiaoyu365.net
ServerAdmin webmaster@localhost

DocumentRoot D:/wamp/www/SNS

<Directory D:/wamp/www/SNS>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
</VirtualHost>


<VirtualHost api.app.jiaoyu365.net>
ServerName api.app.jiaoyu365.net>
ServerAdmin webmaster@localhost

DocumentRoot D:/wamp/www/app_api

<Directory D:/wamp/www/app_api>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
</VirtualHost>


<VirtualHost c.jiaoyu365.net>
ServerName c.jiaoyu365.net
ServerAdmin webmaster@localhost

DocumentRoot D:/wamp/www/CSNS

<Directory D:/wamp/www/CSNS>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
</VirtualHost>

/*********************************

提问 为什么不论输入什么地址总是从第一个配置项目录进入呢?
百思得不得其解,哪位大侠给解释下。

ps:hosts里配置的地址都能ping通
...全文
267 3 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
mestyc 2011-11-07
  • 打赏
  • 举报
回复
配置虚拟主机用httpd-vhosts方便些吧。
把httpd.conf里面#Include conf/extra/httpd-vhosts.conf前面的注释删掉。
然后配置conf/extra/httpd-vhosts.conf
给你个完整的配置。
#
# Virtual Hosts
#
# If you want to maintain multiple domains/hostnames on your
# machine you can setup VirtualHost containers for them. Most configurations
# use only name-based virtual hosts so the server doesn't need to worry about
# IP addresses. This is indicated by the asterisks in the directives below.
#
# Please see the documentation at
# <URL:http://httpd.apache.org/docs/2.2/vhosts/>
# for further details before you try to setup virtual hosts.
#
# You may use the command line option '-S' to verify your virtual host
# configuration.

#
# Use name-based virtual hosting.
#
NameVirtualHost *:80

#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ServerName or ServerAlias in any <VirtualHost> block.
#
<VirtualHost *:80>
ServerAdmin master@localhost
DocumentRoot "D:/Apache/htdocs"
ErrorLog "logs/web-error.log"
CustomLog "logs/web-access.log" common
<Location />
Order Allow,Deny
deny from all
</Location>
</VirtualHost>

<VirtualHost *:80>
ServerAdmin master@localhost
DocumentRoot "D:/wamp/www/school"
ServerName school.jiaoyu365.net
ErrorLog "logs/web-error.log"
CustomLog "logs/web-access.log" common
</VirtualHost>

<VirtualHost *:80>
ServerAdmin master@localhost
DocumentRoot "D:/wamp/www/SNS"
ServerName m.jiaoyu365.net
ErrorLog "logs/web-error.log"
CustomLog "logs/web-access.log" common
</VirtualHost>
adrlanoqq 2011-11-05
  • 打赏
  • 举报
回复
没组织好,可能不是很好的格式,大侠们讲究着看看吧。[挖鼻屎]

24,923

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 Apache
社区管理员
  • Apache
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧