Apache virtual host problem Half solved

Derek Broughton news at pointerstop.ca
Tue Feb 5 15:46:44 UTC 2008


Ashley Benton wrote:

> I was able to set the computer which the files are on to see that it has
> more than one virtual host by adding a line at the end of
> /etc/apache2/apache2.conf
> "Include the virtual host configuration and listing every virtual host I
> wanted."

> I deleted the first line NameVirtualHost for the 2 new VirtualHost and
> don't have the error message that NameVirtualHost has no host, so
> everything seems fine.

I think that's only a warning - I get "[warn] NameVirtualHost *:0 has no
VirtualHosts" every time I start, I've been unable to get rid of it (and
neither has anybody else I've seen via google), and all my vhosts work.

> My problem now is to open this page with another computer on the
> network.http://192.168.0.105/www.theswebsite.com

That's not how virtual hosts work.  

Here's what I have:

NameVirtualHost *
<VirtualHost *>
  ServerName nagisa
  ServerAlias nagisa.pointerstop.ca
  ...
</VirtualHost>
<VirtualHost *>
  ServerName plonevdc
  ServerAlias plonevdc.pointerstop.ca
  ...
</VirtualHost>

My /etc/hosts has:

127.0.0.1 localhost
127.0.2.1 nagisa.pointerstop.ca nagisa
127.0.2.2 plonevdc.pointerstop.ca plonevdc

For any other host on the local subnet, /etc/hosts has to include (using
your IP):

192.168.0.105 nagisa.pointerstop.ca nagisa
192.168.0.105 plonevdc.pointerstop.ca plonevdc

[One of these days, I'll get around to figuring out how to put cnames into
the DNS on my router so that I don't need that...]

Now, you access plonevdc via http://plonevdc/path or
http://plonevdc.pointerstop.ca/path from any machine on my lan.  Apache
looks at the http headers and sees what was _requested_ and directs to the
appropriate vhost.  It doesn't care what IP was actually used (unless you
manually specify an IP in either NameVirtualHost or <VirtualHost>.  That's
why it's best not to use NameVirtualHost 192.168.0.105 - this means that
all network requests have to come _from_ the external network, and you
can't get there via http://localhost/ - or any name that translates to
127.x.x.x).

If you manually specify the IP in the http request, it _never_ goes to the
virtual host, because the IP is not given as a ServerAlias in any virtual
host spec.
-- 
derek





More information about the ubuntu-users mailing list