TCLUG Archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [TCLUG:20771] Creating virtual hosts



Apu said:
> Does anyone know how to create virtual hosts using ifconfig ? Is it possible that I can extend my IP address with wild cards and make so that I can host many sites having a single static IP in my machine.

These are two separate things.  If you use ifconfig to set up virtual hosts,
you'll be assigning many IP addresses to a single machine.  If you use
apache's virtual-hosts-by-name feature to host multiple sites on a single IP
address, then you'll only be assigning a single IP address to the machine.

To do it with ifconfig, you just need to build your kernel with the
appropriate module and then assign IP addresses to eth0, eth0:0, eth0:1, etc.

The disadvantage of this approach is that you need a separate IP address for
each site you host and IP addresses are coming to be considered a scarce
commodity which really shouldn't be wasted like that.  It may also require
you to rebuild your kernel if the appropriate module isn't in your current
one.

To do virtual (web) hosting on a single IP address, add lines of the
following form to your httpd.conf:

---
# IP address for name-based virtual hosting
NameVirtualHost 111.222.333.444

# Dummy default entry to catch requests from pre-HTTP 1.1 browsers and ask
# them which virtual domain they wanted
<VirtualHost 111.222.333.444>
DocumentRoot /var/www
</VirtualHost>

<VirtualHost www.firstdomain.com>
ServerName www.firstdomain.com
ServerAlias firstdomain.com *.firstdomain.com
DocumentRoot /var/www/firstdomain.com
ServerPath /firstdomain.com
</VirtualHost>

<VirtualHost www.seconddomain.org>
ServerName www.seconddomain.org
ServerAlias seconddomain.org *.seconddomain.org
DocumentRoot /var/www/seconddomain.org
ServerPath /seconddomain.org
</VirtualHost>
---

The primary (only?) limitation of this approach are that it relies on the
HTTP 1.1 Host: header.  This can be worked around by using the default
'where do you want to go' page mentioned in the comment above, including
the ServerPath directive for each virtual host, and only using relative
paths within each virtual site's content.

-- 
"Two words: Windows survives." - Craig Mundie, Microsoft senior strategist
"So does syphillis. Good thing we have penicillin." - Matthew Alton
Geek Code 3.1:  GCS d- s+: a- C++ UL++$ P+>+++ L+++>++++ E- W--(++) N+ o+
!K w---$ O M- V? PS+ PE Y+ PGP t 5++ X+ R++ tv b+ DI++++ D G e* h+ r++ y+