1. Win10系统上,“开始”->“所有应用”->“Windows附件”->“记事本”,右键“以管理员身份运行”记事本。选择“文件”->“打开”菜单,进入“C:WindowsSystem32driversetc”目录,未看到任何文件(Windows隐藏了),在“文件名”处键入“hosts”,按“打开”。即可编辑hosts文件。
2. 复制localhost的那行,将新行的“localhost”改成wuxing-testing.info;
127.0.0.1 wuxing-testing.info
3. 编辑D:/wamp/bin/apache/apache2.4.9/conf,开启虚拟主机配置文件:
# Virtual hosts
Include conf/extra/httpd-vhosts.conf
4. 修改conf/extra/httpd-vhosts.conf,在文件末尾加上如下配置:
<VirtualHost *:80>
DocumentRoot "D:/wamp/www"
ServerName localhost
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "D:/wuxing-testing.info"
ServerName wuxing-testing.info
</VirtualHost>
<Directory "D:/ wuxing-testing.info">
Options Indexes FollowSymLinks
AllowOverride all
<IfDefine APACHE24>
Require local
</IfDefine>
<IfDefine !APACHE24>
Order Deny,Allow
# Deny from all
# Allow from localhost ::1 127.0.0.1
Allow from all
</IfDefine>
</Directory>
LoadModule rewrite_module modules/mod_rewrite.so
至此配置完成。
Hosts域名不带www,在虚拟主机配置ServerAlias,试图让Apache解析带www域名之后,发现在本机环境根本不起作用。可能是因为"www”这个主机名和DNS服务紧密相关吧。