Page 1 of 1

pointing domain to localhost via apache virtual hosts

Posted: Sat May 26, 2007 7:36 pm
by s.dot

Code: Select all

#
# Use name-based virtual hosting.
#
NameVirtualHost *:80

#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for requests without a known
# server name.
#
<VirtualHost *:80> 
  DocumentRoot C:/Apache2/htdocs 
  ServerName localhost 
</VirtualHost> 

<VirtualHost *:80>
   DocumentRoot C:/Apache2/htdocs/me
   ServerName localhost
</VirtualHost>
I've tried tons of combinations, but the actual domain (http://www.domain.com) will only go to the /htdocs/ root, and not to /htdocs/me

:?:

Posted: Sat May 26, 2007 9:12 pm
by hawleyjr
You need to edit your HOSTS file.

C:\WINDOWS\system32\drivers\etc\hosts

Posted: Sat May 26, 2007 10:55 pm
by s.dot
OK.

So I've got the domain registered pointing the DNS at my IP address. This works and I see the document root displayed.

So now I'm wanting to point this domain to /doc_root/me/.

I edited my hosts file so it looks like this:

Code: Select all

127.0.0.1       localhost
my.ip.addr.ess	mydomain.com
My virtual hosts section in httpd.conf looks like this:

Code: Select all

<VirtualHost *:80>
   DocumentRoot C:/Apache2/htdocs
   ServerName localhost
</VirtualHost>

<VirtualHost *:80>
   DocumentRoot C:/Apache2/htdocs/me
   ServerName mydomain.com
</VirtualHost>
I've played around with lots of settings in the second virtual host container but can't seem to get it to work. It's still pointing to the document root that's in the first virual host container. Short of restarting my machine (in case the 'hosts' file needs to be recognized at startup), I'm not sure what to do.

Posted: Sat May 26, 2007 11:26 pm
by s.dot
I should note that I'm running apache on windows vista. Probably doesn't make a difference, but just in case.

I followed this document to a T: http://apptools.com/phptools/virtualhost.php
Seems like it should work.

I may just give up and run the /me folder directly inside of /htdocs. But it would suck if I need to add another web site to my development area.

Posted: Sun May 27, 2007 2:59 am
by timvw
Your host file isn't right yet (notice that space between the two.. It's possible that it works if you place the ip hostname pair on an extra line, but i haven't tried that, since this works already ;)

127.0.0.1 localhost mydomain.com

Posted: Sun May 27, 2007 11:54 am
by s.dot
OK, so now my host file looks like this:

Code: Select all

127.0.0.1 localhost mydomain.com
and my virtual hosts looks like this

Code: Select all

NameVirtualHost *:80

<VirtualHost *:80>
   DocumentRoot C:/Apache2/htdocs
   ServerName localhost
</VirtualHost>

<VirtualHost *:80>
   DocumentRoot C:/Apache2/htdocs/me
   ServerName mydomain.com
</VirtualHost>
Anything I am doing wrong? :? mydomain.com still goes to C:/Apache2/htdocs

Posted: Sun May 27, 2007 3:03 pm
by hawleyjr
I'm not at my pc that is running apache so I can't test this. but have you tried this:

Code: Select all

127.0.0.1 localhost 
127.0.0.1 mydomain.com

Posted: Sun May 27, 2007 5:25 pm
by s.dot
hawleyjr wrote:I'm not at my pc that is running apache so I can't test this. but have you tried this:

Code: Select all

127.0.0.1 localhost 
127.0.0.1 mydomain.com
Yes. That didn't work either. I just set my domain as the root. And if I need to develop additional sites, i'll just park them at mydomain.com/site_name/ for local development.

Posted: Mon May 28, 2007 5:30 am
by timvw
having them on a separate line or not, shouldn't matter... Your httpd.conf looked allright too..

So the only thing i can imagine is that you haven't restarted your apache after you had made the changes to httpd.conf....