[Techtalk] Apache and name based virtual hosts
Carolyn Hicks
carolyn at bannoy.net
Wed Sep 24 09:44:51 EST 2003
On Tue, Sep 23, 2003 at 09:15:00PM +0200, tiera wrote:
> I'm trying to configure Apache (Apache/2.0.40 (Red Hat Linux)) to use name
> based virtual hosts.
I think you might need a separate NameVirtualHost directive for your SSL
host, and stick to IP addresses or * in the VirtualHost lines (not
servernames).
What works for me is along these lines:
------8<-------8<-------
NameVirtualHost *:80
<VirtualHost *:80>
ServerName example1.com
...
</VirtualHost>
<VirtualHost *:80>
ServerName example2.com
...
</VirtualHost>
NameVirtualHost *:443
<VirtualHost *:443>
ServerName secure.example1.com
...
</VirtualHost>
------8<-------8<-------
I'm using Apache 1.3, not 2.0, but I don't think the VirtualHost config
directives have changed much.
> If I visit
> https://example1.com/page.html everythings ok. If I visit
> https://example2.com/page.html I get the same page as before, which I don't
> think should work because page.html is in the document root for example1.com.
I think that's exactly how it should work :)
You've only defined one virtualhost on port 443, so it doesn't matter
which servername you enter; if you're using https and going to port 443,
the results will be served by the only *:443 virtualhost Apache knows
about.
> I've tried to put example1.com instead of the *
> in the above configuration directives, but then I get different errors about
> missing NameVirtualHost and that example2.com doesn't belong and so on.
Yes, you need to put IP or * in the VirtualHost directive, a servername
won't work. It does seem a bit counter-intuitive, like if they're
"name-based" virtual hosts you should be able to define each one by its
name - but that's not how Apache thinks about it :)
hope that helps,
Carolyn
More information about the Techtalk
mailing list