Apache and hosts.

hugheba

Registered
In IIS I am able to use one IP address for multible hosts on a domain.

I have my DNS pointing

www.mydomain.com
www2.mydomain.com
www3.mydomain.com
testing.mydomain.com
...and a handfull of others...

to the same box with one IP address. MS IIS catches the hosts (www, www2, www3, ...) and pulls from the corresponding virtual web and publishes it to that as a site from a particular folder.

Is this possible with apache and MacOSX? If so, how do I do it?
 
hugheba,

you should be able to do that with virtual hosts in apache. In your httpd.conf file there is a section near the bottom where you can use virtual hosts. I'll try and find a good web site on how to edit it.

IIS can also redirect based on header info, i'm pretty sure apache can do that as well but it escapes me on where in the httpd.conf the setting are.

maybe someone else can point you in the right direction?

-B
 
In /etc/httpd you will find the httpd.conf file. Go to the end of the file and add (see the commented out example for more options):

Code:
NameVirtualHost *

Include /private/etc/httpd/users

<VirtualHost _default_ >
DocumentRoot /rootdirectoryofww
ServerName mydomain.com
</VirtualHost>

<VirtualHost _default_ >
DocumentRoot /rootdirectoryofww2
ServerName www2.mydomain.com
</VirtualHost>

<VirtualHost _default_ >
DocumentRoot /rootdirectoryofww3
ServerName www3.mydomain.com
ServerAlias alias.mydomain.com bigdeal.myotherdomain.com
</VirtualHost>

Don't think of it as having a main server with extra virtual servers, though. Think of it as either one non-virtual, or all virtual.
 
Anyone have any luck getting this to work. My config for Virtual Hosts looks just like yours. My questions is do I have to comment of the DocumentRoot line that is outside of these containers in the main config. When I have them uncommented they go to the wrong Doc root. They don't go to the ones I set. If I comment it out it just gives me a 404 error...what am I doing wrong...please any help???

Spencer Parker
 
When I set this up, I didn't need to comment anything out.

The file you want to edit is, indeed, httpd.conf (it *may* be different in OS X before 10.1.3).

It should be located at /private/etc/httpd/httpd.conf (since it's in /private, Sherlock will not find it).

You'll want to put the container at the end of the file, but before any Include statements.

The html documentation for this can be found here:
/Library/Documentation/Services/apache/vhosts/index.html.en

Also, the httpd.conf file on all the OS X boxes I have access to (a couple different versions of X) all have extensive commenting, so you can just read through that for more detail.

One other note, if your server doesn't have it's own static, public IP address, you'll probably need to give it the NameVirtualHost command and then specify the private IP of that machine (i.e. You've got DSL with 1 static IP but you're sharing it with 3 computers using 10.x or 192.168.x addresses), otherwise Apache seems to get confused. That could be resulting in 404 errors. Also, it sounds silly, but make sure the path you specify for DocumentRoot is correct.
 
Back
Top