...

View Full Version : VirtualHost Problems.. what am I don't wrong?



tylerjca
06-12-2007, 02:44 AM
Hi, I'm trying to set up Virtual Hosts on my local server (Not public).

I am having problems though. I've done this before and had it work prefectly, but I don't remember how I got it to work last time.. but here's my problem..

In the httpd.conf file, I have added the <VirtualHost> tags for 2 separate sites. But only the "default" (*:80) one works.. BTW, I'm on a Windows system.



NameVirtualHost *:80

<VirtualHost server1:80>
ServerAdmin tyler@localhost
DocumentRoot 'C:/Program Files/xampp/htdocs/tyler'
ServerName server
</VirtualHost>

<VirtualHost *:80>
ServerAdmin admin@localhost
DocumentRoot 'C:/Program Files/xampp/htdocs'
ServerName server
</VirtualHost>


It's server1 that won't work for me. Please tell me what I've done wrong, or any possible things I've missed!

also, i know that the directorie are correct because when i change the DocumentRoot in *:80 to 'C:/Program Files/xampp/htdocs/tyler' it works as expected, but not for the expected VirtualHost

Thanks,
Tyler

_Aerospace_Eng_
06-12-2007, 06:58 AM
Maybe this will help you
http://www.thewatchmakerproject.com/journal/378/virtual-hosts-and-the-proper-way-to-work-offline

I changed my NameVirtualHost from *:80 to 127.0.0.1

NaveVirtualHost 127.0.0.1
Then I used this to set up my new virtual host

<VirtualHost 127.0.0.1>
ServerName mysite.localhost
DocumentRoot "D:\Program Files\xampp\htdocs\somefolder"
</VirtualHost>
Seems like you may have your slashes backwards. Remember to edit the host file under C:\WINDOWS\System32\drivers\etc

After making the changes you will have to restart apache if it was running when you made the changes.

tylerjca
06-12-2007, 03:20 PM
Thanks for the reply :thumbsup: Great resource.
And it seemed like my slashes were in fact backwards. Thanks :)

Now, problem is, it only seems to want me to have 2 virtual hosts.. The 'default' *:80 one works fine, and so does tyler.server.
And then there is another test folder, msgs.server. This one seems to be recognized, but it directs to the same DocumentRoot as tyler.server.. here's my httpd.conf snippet:


NameVirtualHost *:80

<VirtualHost 127.0.0.1>
ServerName tyler.server
DocumentRoot 'C:\program files\xampp\htdocs\tyler'
</VirtualHost>

<VirtualHost 127.0.0.1>
ServerName msgs.server
DocumentRoot 'C:\program files\xampp\htdocs\emessages\msgs'
</VirtualHost>

<VirtualHost *:80>
ServerName localhost
DocumentRoot 'C:\Program Files\xampp\htdocs\'
</VirtualHost>


Is there a limit on the number of VirtualHosts you can have? If so, I doubt it's only 2!

_Aerospace_Eng_
06-12-2007, 06:58 PM
No I setup 3 of them. Reread my post. Check out what I did to the NameVirtualHost. I changed instances of *:80 to 127.0.0.1
Again make sure you edit your hosts file.

tylerjca
06-13-2007, 12:54 AM
okay, i'm an idiot.. I got it working.. i was trying different combinations of 127.0.0.1 and *:80 and etc.. and I had the hosts file set for:
127.0.0.1 server
but I guess it needed to have each name registered .. so i now have


127.0.0.1 server
127.0.0.1 tyler
127.0.0.1 messages


And in httpd.conf:


NameVirtualHost 127.0.0.1

<VirtualHost 127.0.0.1>
ServerName messages
DocumentRoot 'C:\program files\xampp\htdocs\emessages\msgs'
</VirtualHost>

<VirtualHost 127.0.0.1>
ServerName tyler
DocumentRoot 'C:\program files\xampp\htdocs\tyler'
</VirtualHost>

<VirtualHost 127.0.0.1>
ServerName localhost
DocumentRoot 'C:\Program Files\xampp\htdocs\forum'
</VirtualHost>


So everything seems to be working now. Thanks for your help, _Aerospace_Eng_!

_Aerospace_Eng_
06-13-2007, 05:29 AM
You can also do this with your hosts file

127.0.0.1 server, tyler, messages
which is the equivalent of

127.0.0.1 server
127.0.0.1 tyler
127.0.0.1 messages
Though it appears you replaced localhost with server. I think that should be set to localhost.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum