Virtual Hosting Problems

Carl Turner cturner at kchost.com
Thu Apr 17 11:22:34 CDT 2003


I wouldn't suggest using '*' for the <VirtualHost> entries.
Makes for a busy httpd process when the virtual domains start piling
up. And I've got the before and after graphs to prove it! :)

For name based virtual hosting (I gathered this is what you are
attempting) to work properly, you need to do the following...
In the httpd.conf the following must be set:
BindAddress <ip || '*'> #this is the IP address that the hostnames resolve
to
NameVirtualHost <ip:port> #same as above, but gives you the option of the
port. This value must be set for name based virt hosting

ie...
BindAddress 192.168.0.1
NameVirtualHost 192.168.0.1:80

As for the <VirtualHost> entries, follow this sample:
<VirtualHost somedoamin.com>
 ServerName www.somedomain.com
 DocumentRoot /path/to/http/files
 #include any other entries specific to this domain such as 'ErrorLog',
etc.
</VirtualHost>

This one entry will cover both formats of the URL that is entered by the
end users browser. You can also add an entry within the <VirtualHost>
called 'ServerAlias'. Which is basicly like 'ServerName', but allows you
to define any other domain names that are pointing to the
'NameVirtualHost' IP that you want this <VirtualHost>'s 'DocumentRoot' to
cover.
ie... say we wanted the alt. of somedomain.com (.org, .net, etc.) to also
be taken care of by this <VirtualHost> entry. We just add a
line: ServerAlias www.somedomain.org somedomain.org www.somedomain.net
somedomain.net

If you are not doing DNS on the same host as your apache server. You will
need to make sure each domain name can be resolved. Or else you will get
the default page to load.
Also make sure the DNS entries for each name is an 'A' ref. not a 'CNAME'
forwarder or it won't work at all.

Hope this helps,
-Carl

On Wed, 16 Apr 2003, Lucas Peet wrote:

> 
> > I don't see how this will work for virtual names. Ever.
> >> <VirtualHost *>
> >>    DocumentRoot /home/http/default
> >>    .....
> >> </VirtualHost>
> 
> Think of the asterisks as 'all inclusive'.  'NameVirtualHost *' would
> mean "don't bother whith the IP address or port - consider all virtual
> hosts equal."  With that in mind, when apache receives a request, since
> there is no definite virtual host, it compares the ServerName and
> ServerAlias with the HTTP header (which contains the URL the user put in
> his address bar), and when finding a match, it serves up the page.
> 
> It's not as much of an issue now as it was 5-8 years ago, but Name based
> virtual hosting will NOT work with browsers earlier than 3.0.  This goes
> with Netscape AND IE.  Of course, that was when IP addresses were more
> plentiful and people could afford to use IP based virtual hosting...
> 
> The only time you should ever use actual IP addresses in a virtual host
> configuration is when you're doing IP based virtual hosting, have a
> large block of IP addresses to assign each virtual host it's own IP, and
> have eth0 assigned a virtual IP as well.
> 
> So...with that in mind...
> 
> NameVirtualHost *
> 
> <VirtualHost *>
> 	ServerName www.domain.com
> 	ServerAlias domain.com
> 	DocumentRoot ...
> </VirtualHost>
> 
> ...is the way to go.
> 
> 
> -Lucas
> 
> 
> -----Original Message-----
> From: owner-kclug at marauder.illiana.net
> [mailto:owner-kclug at marauder.illiana.net] On Behalf Of Brian Densmore
> Sent: Wednesday, April 16, 2003 10:56 AM
> To: kclug at kclug.org; jose sanchez
> Subject: RE: Virtual Hosting Problems
> 
> What do the DNS entries look like for these domains?
> I like to run a local dns on the same box as my server.
> Also try adding the port numbers to the names.
> 
> <VirtualHost www.kcmultiservice.com:80>
>    ServerName www.kcmultiservice.com
>    .....
> </VirtualHost>
> ...
> 
> I don't see how this will work for virtual names. Ever.
> > <VirtualHost *>
> >    DocumentRoot /home/http/default
> >    .....
> > </VirtualHost>
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 




More information about the Kclug mailing list