Forum Moderators: phranque

Message Too Old, No Replies

Virtual Hosts questions

I can't figure out how to set them up

         

MatthewHSE

12:17 am on Jul 13, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm trying to set up a small development server. At the moment, I took the easy way out and set up XAMPP on my Windows XP box. I'd like to be able to set things up so that certain web addresses get routed directly to a virtual host using a separate directory within my htdocs directory. In other words, typing (for instance) www.site1.com would load up the index page in /htdocs/site1/ on my localhost.

As I see it, I have two things to do. First, add a line to my Windows HOSTS file so that all requests for www.site1.com go to 127.0.0.1. Second, add the virtual host for www.site1.com to my httpd.conf file so that Apache directs requests for that domain to the proper directory on my local drive.

My problem is I don't know how to set up the virtual host section. I've read through several online tutorials, but none of them seem to make anything very clear.

I want all requests for www.site1.com to be routed to C:\xampp\htdocs\site1

My specific questions are going to seem like "please do my homework for me" type of questions, but I'm really lost. So if someone could just give me the answers, then possibly explain a bit of the reasoning behind the answers, I'm sure I'll be able to do this alone next time! ;)

So anyway, here are the questions I have right now:

  1. Do I need to use name-based virtual hosting?
  2. What goes in the "start tag" of <VirtualHost>, as in, <VirtualHost whatgoeshere>
  3. What should my ServerName and DocumentRoot be?
  4. Is there anything I'm missing, overlooking, or have wrong?

What I've Done So Far:

So far, I've added the following line to my Windows hosts file:

127.0.0.1 www.site1.com

So far so good; whenever I have Apache running and try to go to www.site1.com it goes right to the index page in my /htdocs directory.

I've also tried adding the Virtual Host to my httpd.conf file:

<VirtualHost *>
ServerName www.site1.com
DocumentRoot /htdocs/site1
DirectoryIndex index.html
</VirtualHost>

For the DocumentRoot line, I've tried using forward / and backward \, and have tried both kinds of slashes with full and relative paths. None of it has any effect; going to www.site1.com still loads up the index page for /htdocs instead of the index page for /htdocs/site1.

Any and all help to get this straightened out will be greatly appreciated.

Matthew

encyclo

1:12 am on Jul 13, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



<VirtualHost *>
ServerName www.site1.com
DocumentRoot /htdocs/site1
DirectoryIndex index.html
</VirtualHost>

The basic syntax looks good, but your path is wrong. Most of the examples in the Apache documentation are for use on Linux/other Unix servers where the paths use slashes and no drive name. In your case, you need to specify the full Windows path to the document root. You should also start your list of virtual hosts with a

NameVirtualHost *
as well if you haven't already got it:

NameVirtualHost *
<VirtualHost *>
ServerName www.site1.com
[b]DocumentRoot C:\xampp\htdocs\site1[/b]
DirectoryIndex index.html
</VirtualHost>

Once this is in your httpd.conf, restart Apache. If it fails to restart, check the error log for details. Other than that, your approach looks good!