How to enable and configure Virtual hosts, vhosts, in Apache2.
Last Updated: 2006-09-27
How to enable and configure Virtual hosts, vhosts, in Apache2.
Virtual hosts or vhosts enable you to host multiple domain names on one IP address. The configuration is Apache2 looks a little more complicated at first because it is spread out over so many files.
The configuration options explained below are written for a SuSE 10 installation with Apache2. Other distros might have a different configuration layout. Use
Command:
|
This Guide assumes that you have Apache2 installed and configured for Single domain use. If you enter the server's IP/domain into your browser you should see the Apache2 generated test page or your website. If not, check Virtual Brain Online for suggestions.
I strongly recommend that you make a backup before you begin
A simple tar backup of your config folder will do
Command:
|
Your backup file is now called apache2_config_backup_pre_virutalhost.tar.gz and contains all your config files under /etc/apache2.
Since I'm using SuSE 10 on my server, I double checked the settings in /etc/sysconfig/apache2
Now we need to make sure that Apache2 will actually listen for a connection to one of it's VirtualHosts.
Open listen.conf and change
#NameVirtualHost *:80
to
NameVirtualHost *:80
Next, open the default-server.conf, which is located in /etc/apache2/default-server.conf in SuSE Linux
The default-server.conf contains all the default server settings. This is also the place where I give permission to browse my server root. Adjust the configuration options below to match your own setup.
DocumentRoot /mnt/raid5/srv/www/htdocs/network-technologies.org/
<Directory "/mnt/raid5/srv/www/htdocs/">
Order allow,deny
DirectoryIndex index.php index.html
IndexOptions FancyIndexing HTMLTable VersionSort
UseCanonicalName off
Allow from all
</Directory>
All that's left now is to create the virtual hosts configuration file, apache2 wants all VirtualHost configuration stored in the directory apache2/vhosts.d/
I would recommend that you create one file per parent domain and one catch all file, this will make maintenance a lot simpler. At the time of writing, I have three files in my vhosts.d directory.
2of9:/etc/apache2/vhosts.d # ls -l
-rw-r--r-- 1 root root 292 Nov 26 10:26 catch_all.conf
-rw-r--r-- 1 root root 645 Nov 26 10:22 mirkokaiser.com.conf
-rw-r--r-- 1 root root 1468 Nov 26 10:20 network-technologies.org.conf
And each file contains:
File:
|
File:
|
File:
|
Restart your server, give it a try and let me know how it went.
Originally Posted by Skylinux @ 2005-11-26 10:46:40
Bug Fix in BB Tags
Last update by Skylinux @ 2005-11-26 17:08:45
Make sure that the configuration file ends with .conf or apache will not read it from your virtual hosts folder.
Last update by Skylinux @ 2005-12-28 21:50:46
No Comments yet .....
Add Your Comment:
Note: All posts require administrator approval. Please allow 24 hours for message approval.