Virtual Hosts on Apache

Problems with the Windows version of XAMPP, questions, comments, and anything related.

Virtual Hosts on Apache

Postby ChrisNY » 17. August 2009 17:36

Hi;

I have my localhost, with the document root say at: "E:/app/SymLink_DoNotDelete/". Within that directory, I have several subdirectories, including E:/app/SymLink_DoNotDelete/overheard. If I just entered "http://localhost" in my browser, I got the localhost directory listing. If I typed http://localhost/overheard, I got the webpage in the "overheard" directory.

But I wanted to be able to access the "overheard" site by just entering "http://overheard", for various obvious reasons. So I tried virtual hosts.

I've got virtual hosts working (sort of) on my local development version of Apache -- that is, when I type in the URL http://overheard, I get the appropriate webpage.

However, now http://localhost also gives the contents of the "overheard" subdirectory, so I did something wrong. Here is the entry I made in my httpd.conf file, at the end:

Code: Select all
<VirtualHost overheard>
    ServerName   overheard
    DocumentRoot "E:/app/SymLink_DoNotDelete/overheard/public"
</VirtualHost>


Can anyone tell me how to get my original localhost back (to my document root), while still keeping my virtual host "Overheard" pointing to the overheard directory?

Thanks.
ChrisNY
 
Posts: 3
Joined: 19. June 2009 08:25

Re: Virtual Hosts on Apache

Postby Wiedmann » 17. August 2009 18:05

Can anyone tell me how to get my original localhost back (to my document root), while still keeping my virtual host "Overheard" pointing to the overheard directory?

Add a virtual host for "localhost".
Wiedmann
AF Moderator
 
Posts: 17106
Joined: 01. February 2004 12:38
Location: Stuttgart / Germany

Re: Virtual Hosts on Apache

Postby ChrisNY » 17. August 2009 19:28

Hi, thanks; that seemed like the perfect answer, but when I tried it, then everything (both localhost & overheard) resolved to the original localhost path. Especially odd since I put the Localhost definition before the overheard definition, so you would think if one overwrote the other, it would be the last, overheard. Could I have made some syntax or argument error in the virtual host declaration? This is what I put at the end of my httpd.conf file:

Code: Select all
<VirtualHost localhost>
    ServerName   localhost
    DocumentRoot "E:/app/SymLink_DoNotDelete"
</VirtualHost>

<VirtualHost overheard>
    ServerName   overheard
    DocumentRoot "E:/app/SymLink_DoNotDelete/overheard/public"
</VirtualHost>


Thanks again for your suggestion; it should have worked...
ChrisNY
 
Posts: 3
Joined: 19. June 2009 08:25

Re: Virtual Hosts on Apache

Postby Wiedmann » 17. August 2009 20:22

You want use namebased virtual hosts (all hostnames have the same ip)?
Wiedmann
AF Moderator
 
Posts: 17106
Joined: 01. February 2004 12:38
Location: Stuttgart / Germany

Re: Virtual Hosts on Apache

Postby Izzy » 17. August 2009 22:17

First remove the virtualhost entries from the httpd.conf file then save the file and try and restart Apache to make sure the httpd.conf file is syntactically correct.

Next use \xampp\apache\conf\extra\httpd-vhost.conf file to add your entries for example:
Code: Select all
NameVirtualHost *:80

<VirtualHost *:80>
    ServerName   localhost
    DocumentRoot "E:/app/SymLink_DoNotDelete"
</VirtualHost>

<VirtualHost *:80>
    ServerName   overheard
    DocumentRoot "E:/app/SymLink_DoNotDelete/overheard/public"
</VirtualHost>
Save the file after editing.

Next open \Windows\system32\drivers\etc\hosts file by dragging it into your text editor (in Vista right click on the text editor and select to run as administrator then Open the above file).

make sure your have these 2 entries first and if not then add them:
Code: Select all
127.0.0.1 localhost
127.0.0.1 overheard
Save the file and now restart Apache and see if that works for you.

BTW always a good idea to keep clearing your browser's cache when working at localhost level or you may be served a cached page instead of a newly edited page.
Izzy
 
Posts: 3344
Joined: 25. April 2006 17:06


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 57 guests