Setting up subdomain for local development

901 Views Asked by At

I have XAMPP installed for local development and I'd like to create a sub domain for each project. In my apache vhosts config I've put this:

<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 [email protected]
</VirtualHost>

And in my Windows hosts file:

# development
127.0.0.1 localhost
127.0.0.1 nexus.localhost

localhost works as normal. As in, if I go to http://localhost/project_name everything works fine. However, if I navigate to http://nexus.localhost/ I just get Object not found! errors.

What could be wrong here? Thank you.

1

There are 1 best solutions below

2
On

The documentation http://httpd.apache.org/docs/2.2/mod/core.html#virtualhost says that the <VirtualHost> directive should contain the IP address, so try this instead:

<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 [email protected]
</VirtualHost>