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通
...全文
254 3 打赏 收藏 转发到动态 举报
写回复
用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
  • 打赏
  • 举报
回复
没组织好,可能不是很好的格式,大侠们讲究着看看吧。[挖鼻屎]
CentOS 6.5 apache网站服务器配置实例 【例题】 配置apache服务器,服务器IP为10.11.23.21,创建两个基于域名的虚拟主机网站,网站 主目录分别为/www/web01,/www/web02,要求使用域名inner1.test.com和inner2.test .com进行访问,制作简单主页,第一个网站显示为"this is web one",第二个网站显示"this is web two";要求第一个网站只允许192.168.1.0/24网段的用户访问,其他人都不能访问,第 二个网站需要用户登录认证,用户名为webtest,密码为admin123456。 【配置】 1. 在test.com的正反解析文件里添加下列字段为域名做解析: 正向解析: inner1 A 10.11.23.21 inner2 A 10.11.23.21 反向解析: 21 PTR inner1.test.com. 21 PTR inner2.test.com. 2. 安装httpd服务器程序包: #yum install httpd –y #用yum安装httpd程序包 3. 创建网站主目录和主页,用户等: #mkdir –p /www/web01 /www/web02 #同时创建这两个目录,-p是创建多层目录 #echo this is web one > /www/web01/index.html #直接写入内容到index.html #echo this is web two > /www/web02/index.html #同上,并创建这个文件 #mkdir /data #创建保存登陆认证用户文件的目录(可以自定义) #touch /data/.htpasswd #创建保存网站登录认证的用户文件 #htpasswd –c /data/.htpasswd webtest #创建一个网站认证的用户,第一次要加- c, 后面就根据提示输入密码 4. 编辑主配置文件,修改添加下列字段(虚拟主机配置在最后面) #vim /etc/httpd/conf/httpd.conf #编辑主配置文件 NmeVirtualost 10.11.23.21 #设置虚拟主机所使用的IP地址 <VirtualHost inner1.test.com> #这里可以设置IP地址或者域名 # ServerAdmin webmaster@dummy-host.example.com DocumentRoot /www/web01 #去掉注释,设置网站的根目录 ServerName inner1.test.com #虚拟主机的FQDN(域名) # ErroLog logs/dummy-host.example.com-error_log # CustomLog logs/dummy-host.example.com-access_log common #对网站设置访问权限 order deny,allow #先拒绝然后后允许 deny from all #拒绝所有人访问 allow from 192.168.1.0/24 #允许192.168.1.0/24网段访问 VirtualHost> <VirtualHost inner2.test.com> #复制一份,第二个虚拟主机 # ServerAdmin webmaster@dummy-host.example.com DocumentRoot /www/web02 #第二个网站的根目录 ServerName inner2.test.com #虚拟主机的FQDN(域名) # ErroLog logs/dummy-host.example.com-error_log # CustomLog logs/dummy-host.example.com-access_log common #设置网站的访问权限 AllowOverride authconfig #开启进行认证 Authname "login" #认证时显示的名称(可以自定义) Authtype basic #认证方式类似 Authuserfile /data/.htpasswd #认证使用的账号密码文件路径 require valid-user #认证文件中账号都能登陆 VirtualHost> 5. 启动apache服务器: #service httpd start #启动httpd服务 #chkconfig httpd on #设置httpd服务 3 5 级 自启 【测试】 在客户端上使用web

24,923

社区成员

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

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