pointing domain to localhost via apache virtual hosts

Need help installing PHP, configuring a script, or configuring a server? Then come on in and post your questions! We'll try to help the best we can!

Moderator: General Moderators

Post Reply
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

pointing domain to localhost via apache virtual hosts

Post 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

:?:
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

You need to edit your HOSTS file.

C:\WINDOWS\system32\drivers\etc\hosts
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post 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.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post 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.
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post 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
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post 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
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post 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
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post 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.
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post 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....
Post Reply