The term Virtual Host refers to the practice of running more than one web site (such as www.foo.com and www.goo.com) on a single machine. Virtual hosts can be "IP-based", meaning that you have a different IP address for every web site, or "name-based", meaning that you have multiple names running on each IP address. The fact that they are running on the same physical server is not apparent to the end user.
Apache was one of the first servers to support IP-based virtual hosts right out of the box. Versions 1.1 and later of Apache support both IP-based and name-based virtual hosts (vhosts). The latter variant of virtual hosts is sometimes also called host-based or non-IP virtual hosts.
Following are the simple steps for creating/adding virtual hosts in Apache2 under Ubuntu:
Steps #1:
First create the directory structure for holding the webpages and logs for your virtual hosts:
Now, go and create the vhosts file for site foo and goo: vi /etc/apache2/sites-available/foo and add the required contents as shown below:
Similarly create the /etc/apache2/sites-available/foo file for goo site
Steps #4:
Type following command to enable site foo and goo:
Apache was one of the first servers to support IP-based virtual hosts right out of the box. Versions 1.1 and later of Apache support both IP-based and name-based virtual hosts (vhosts). The latter variant of virtual hosts is sometimes also called host-based or non-IP virtual hosts.
Following are the simple steps for creating/adding virtual hosts in Apache2 under Ubuntu:
Steps #1:
First create the directory structure for holding the webpages and logs for your virtual hosts:
sudo mkdir /var/www/fooSteps #2:Add a proper host entry for site foo and site goo into your /etc/hosts file: vi /etc/hosts
sudo mkdir /var/www/goo
sudo mkdir /var/log/apache2/foo
sudo mkdir /var/log/apache2/goo
Steps #3:192.168.1.1 foo192.168.1.1 goo
Now, go and create the vhosts file for site foo and goo: vi /etc/apache2/sites-available/foo and add the required contents as shown below:
<VirtualHost *:80>
ServerAdmin foo-webmaster@localhost
ServerName foo
DocumentRoot /var/www/foo
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/foo/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ErrorLog /var/log/apache2/foo/error.log
LogLevel warn
CustomLog /var/log/apache2/foo/access.log combined
</VirtualHost>
ServerAdmin foo-webmaster@localhost
ServerName foo
DocumentRoot /var/www/foo
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/foo/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ErrorLog /var/log/apache2/foo/error.log
LogLevel warn
CustomLog /var/log/apache2/foo/access.log combined
</VirtualHost>
Similarly create the /etc/apache2/sites-available/foo file for goo site
Steps #4:
Type following command to enable site foo and goo:
sudo a2ensite fooAfter this, restart/reload your apache server using command
sudo a2ensite goo
sudo service apache reloadFinally, after successful apache reload/restart you should able to navigate to site http://foo and http://goo using any browser.
2 comments:
Hi,
For even simpler Vhost management, i've written a little script named "a2tools". It is basicaly a Vhost file templater.
For example, the code you give in your article is basically this command line with a2tools:
a2tools "foo" "/var/www/foo"
More info is available at :
http://howto.biapy.com/en/debian-gnu-linux/servers/http/install-and-setup-apache-2-on-debian
Thank you for your work.
Pierre-Yves Landuré
Biapy
Basically,virtual hosts can be "IP-based", meaning that you have a different IP address for every web site, or "name-based", meaning that you have multiple names running on each IP address. The fact that they are running on the same physical server is not apparent to the end user.
Post a Comment