项目比较多,经常在httpd.conf下来回配置DocumentRoot、directory,比较麻烦。将多个项目配置成多个站点访问就很方便,不便来回修改配置,然后不停重启Apache。
配置方法:
1.打开hosts文件。在C:WindowsSystem32Driversetc目录下。在hosts下增加
127.0.0.1 www.project1.com
127.0.0.1 www.project2.com
127.0.0.1 www.project3.com
2.打开httpd-vhosts.conf文件, 在xamppapacheconfextra目录下。添加
<VirtualHost *:80>
DocumentRoot "E:/xampp/htdocs/project1"
ServerName www.project1.com
<Directory "E:/xampp/htdocs/project1/">
AllowOverride All
</Directory>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "E:/xampp/htdocs/project2"
ServerName www.project2.com
<Directory "E:/xampp/htdocs/project2/">
AllowOverride All
</Directory>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "E:/xampp/htdocs/project3"
ServerName www.project3.com
<Directory "E:/xampp/htdocs/project3/">
AllowOverride All
</Directory>
</VirtualHost>
3.保存所有配置,重启apache。
4.输入www.project.com 就可以访问响应的项目