lindsay_keir
June 15th, 2007, 01:21 AM
I had troubles using Apache2's Virtual Hosts so I thought I'd do a quick How-To to pass on my method. Really, the basic answer is to get an "Alias" defined in apache2.conf (httpd.conf). Anyway ...
Apache2
Link /etc/apache2/mods-available/alias.load => /etc/apache2/mods-enabled
Webmin > Apache > Module Configuration
Change all ../apache/.. files to ../apache2/..
Set (*) Path to httpd.conf or apache2.conf = [/etc/apache2/apache2.conf]
Set (*) Directory to create links in for new virtual servers = [/etc/apache2/sites-enabled]
Webmin > Apache > Define a Virtual Host ...
Document Root [/myGlobal/www/testy1]
Allow access to this directory
Server Name [testy1]
[Create Now]
You will now have a testy1.conf site available and enabled, which looks like ...
<VirtualHost *>
DocumentRoot "/myGlobal/www/testy1"
ServerName testy1
<Directory "/myGlobal/www/testy1">
allow from all
Options +Indexes
</Directory>
</VirtualHost>
This is the important part!
A <VirtualHost *> ignores the declarations for DocumentRoot ServerName Alias and will default to looking for the files under /var/www - So ...
Edit /etc/apache2/apache2.conf - At the end put
# Include the virtual host configurations:
Include /etc/apache2/sites-enabled/
Include /etc/apache2/virtualHosts
Create /etc/apache2/virtualHosts and add your your Virtual Host(s) Alias item(s)
Alias /testy1 "/myGlobal/www/testy1"
Create /myGlobal/www/testy1/index.html
<html>
<head>
<title>testy1</title>
</head>
<body>
<h2 align="center">This is http://localhost/testy1/</h2>
<div align="center"><img src="/icons/apache_pb.gif" alt="" /></div>
</body>
</html>
:phttp://localhost/testy1 is now accessible
Add more Virtual Hosts as wanted - just don't forget to add their Alias to /etc/apache2/virtualHosts:p
:(VirtualDocumentRoot
I read up on VirtualDocumentRoot at http://httpd.apache.org/docs/2.0/mod/mod_vhost_alias.html and it sure looks good, execpt, how do you use it?
I enabled mod_vhost_alias. and modified my testy1 declaration to ...
#DocumentRoot "/myGlobal/www/testy3"
ServerName testy3
<Directory "/myGlobal/www/testy3">
allow from all
Options +Indexes
</Directory>
UseCanonicalName Off
VirtualDocumentRoot /myGlobal/www/testy3
... and tried it - no luck; but it sure looks good. and I would like to use it.:(
Apache2
Link /etc/apache2/mods-available/alias.load => /etc/apache2/mods-enabled
Webmin > Apache > Module Configuration
Change all ../apache/.. files to ../apache2/..
Set (*) Path to httpd.conf or apache2.conf = [/etc/apache2/apache2.conf]
Set (*) Directory to create links in for new virtual servers = [/etc/apache2/sites-enabled]
Webmin > Apache > Define a Virtual Host ...
Document Root [/myGlobal/www/testy1]
Allow access to this directory
Server Name [testy1]
[Create Now]
You will now have a testy1.conf site available and enabled, which looks like ...
<VirtualHost *>
DocumentRoot "/myGlobal/www/testy1"
ServerName testy1
<Directory "/myGlobal/www/testy1">
allow from all
Options +Indexes
</Directory>
</VirtualHost>
This is the important part!
A <VirtualHost *> ignores the declarations for DocumentRoot ServerName Alias and will default to looking for the files under /var/www - So ...
Edit /etc/apache2/apache2.conf - At the end put
# Include the virtual host configurations:
Include /etc/apache2/sites-enabled/
Include /etc/apache2/virtualHosts
Create /etc/apache2/virtualHosts and add your your Virtual Host(s) Alias item(s)
Alias /testy1 "/myGlobal/www/testy1"
Create /myGlobal/www/testy1/index.html
<html>
<head>
<title>testy1</title>
</head>
<body>
<h2 align="center">This is http://localhost/testy1/</h2>
<div align="center"><img src="/icons/apache_pb.gif" alt="" /></div>
</body>
</html>
:phttp://localhost/testy1 is now accessible
Add more Virtual Hosts as wanted - just don't forget to add their Alias to /etc/apache2/virtualHosts:p
:(VirtualDocumentRoot
I read up on VirtualDocumentRoot at http://httpd.apache.org/docs/2.0/mod/mod_vhost_alias.html and it sure looks good, execpt, how do you use it?
I enabled mod_vhost_alias. and modified my testy1 declaration to ...
#DocumentRoot "/myGlobal/www/testy3"
ServerName testy3
<Directory "/myGlobal/www/testy3">
allow from all
Options +Indexes
</Directory>
UseCanonicalName Off
VirtualDocumentRoot /myGlobal/www/testy3
... and tried it - no luck; but it sure looks good. and I would like to use it.:(