基于域名的虚拟主机,就是可以使用同一IP地址,但是域名不同,访问的虚拟主机也不同。服务器通过访问的HTTP-HEADER中请求的域名信息来判断所需要访问的虚拟主机。这就要求配置DNS服务。
一、配置conf/httpd.conf文件
1、打开相应的端口
#Listen 12.34.56.78:82
Listen 82
2、设置服务器的域名,可以保持默认值
ServerName localhost:82
3、设置虚拟主机的目录权限,防止无法访问
<Directory "F:/wamp/www/dede">
Options Indexes FollowSymLinks
AllowOverride all
Order Allow,Deny
Allow from all
</Directory>
4、打开虚拟主机的配置文件
# Virtual hosts
Include conf/extra/httpd-vhosts.confs
二、配置conf/extra/httpd-vhosts.conf文件
NameVirtualHost *:82
#
# 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 *:82>
DocumentRoot "F:/wamp/www/dede"
ServerName www.ynjzy.pp
</VirtualHost>
<VirtualHost *:82>
DocumentRoot "F:/wamp/www"
ServerName www.localhost.pp
</VirtualHost>
三、配置DNS,本机测试修改host文件
127.0.0.1 www.ynjzy.pp
127.0.0.1 www.localhost.pp
重启服务器就可以啦