为本地开发设置子域

时间:2012-05-18 18:59:21

标签: apache xampp virtual-hosts

我安装了XAMPP用于本地开发,我想为每个项目创建一个子域。在我的apache vhosts配置中,我把它放在:

<VirtualHost localhost:80>
DocumentRoot C:/xampp/htdocs/
ServerName localhost
ServerAdmin admin@localhost
</VirtualHost>

<VirtualHost nexus.localhost:80>
DocumentRoot C:/xampp/htdocs/nexus/
ServerName nexus.localhost
ServerAdmin admin@nexus.localhost
</VirtualHost>

在我的Windows主机文件中:

# development
127.0.0.1 localhost
127.0.0.1 nexus.localhost

localhost正常工作。如同,如果我去http://localhost/project_name一切正常。但是,如果我导航到http://nexus.localhost/,我只会收到Object not found!错误。

这里有什么问题?谢谢。

1 个答案:

答案 0 :(得分:0)

文档http://httpd.apache.org/docs/2.2/mod/core.html#virtualhost表示<VirtualHost>指令应包含IP地址,因此请尝试以下操作:

<VirtualHost 127.0.0.1:80>
DocumentRoot C:/xampp/htdocs/
ServerName localhost
ServerAdmin admin@localhost
</VirtualHost>

<VirtualHost 127.0.0.1:80>
DocumentRoot C:/xampp/htdocs/nexus/
ServerName nexus.localhost
ServerAdmin admin@nexus.localhost
</VirtualHost>