Apache Modules mod vhost alias
From Gentoo Linux Wiki
|
|
|
Main Modules
Addons & Tunnels Tips Configuring Other |
| edit |
Here is an example of utilizing Apache's mod_vhost_alias module for dynamic virtual hosting.
| File: /etc/conf.d/apache2 |
... APACHE2_OPTS="-D DYNAMIC_VHOSTS -D PHP5" ... |
| File: /etc/apache2/httpd.conf |
... LoadModule vhost_alias_module modules/mod_vhost_alias.so ... |
Note: The CustomLog directive in 10_dynamic_vhosts.conf is set to log into <local_dir>/logs. By default, current Gentoo installations of apache2 have this set to /usr/apache. This will not work in most cases
| File: /etc/apache2/vhosts.d/10_dynamic_vhosts.conf |
### Dynamic Virtual Hosts
#
# Dynamic VirtualHost: If you want to maintain multiple domains/hostnames on
# your machine and have the process be semi-automatted, you can enable dynamic
# virtual hosts. Apache will automatically host folders under /var/www/vhosts
# as their corresponding domain names. An example of this is:
# If you create the folder example.com under /var/www/vhosts, now Apache can
# serve pages for example.com using the /var/www/vhosts/example.com folder.
#
# Hint: Aliasing the sub-domain www.[example.com] can be easily accomplished
# by simply simlinking www.[example.com] to [example.com].
#
# Please see the documentation at
# <URL:http://httpd.apache.org/docs-2.0/vhosts/>
# and
# <URL:http://www.apache.org/docs/vhosts/mass.html>
# for further details before you try to setup virtual hosts.
#
# Note: Dynamic Virtual Hosts uses the mod_vhost_alias apache module.
<IfDefine DYNAMIC_VHOSTS>
#
# Use name-based virtual hosting.
#
NameVirtualHost *:80
UseCanonicalName Off
LogFormat "%V %h %l %u %t \"%r\" %s %b \"%{Referer}i\" \"%{User-Agent}i\"" dynamic_vhosts
CustomLog logs/access_log dynamic_vhosts
<VirtualHost *:80>
#
# Security Directive
#
<Directory "/var/www/vhosts">
#
# Possible values for the Options directive are "None", "All",
# or any combination of:
# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
# The Options directive is both complicated and important. Please see
# http://httpd.apache.org/docs-2.0/mod/core.html#options
# for more information.
#
Options -Indexes FollowSymLinks MultiViews
#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# Options FileInfo AuthConfig Limit
#
AllowOverride All
#
# Controls who can get stuff from the dynamic virtual hosts.
#
Order allow,deny
Allow from all
</Directory>
# Dynamic Virtual Host Definitions
#
<IfModule mod_vhost_alias.c>
# example.com --> /var/www/vhosts/example.com/htdocs
# www.example.com --> /var/www/vhosts/www.example.com/htdocs
# a.www.example.com --> /var/www/vhosts/a.www.example.com/htdocs
# www.example.com/cgi-bin --> /var/www/vhosts/www.example.com/cgi-bin
VirtualDocumentRoot /var/www/vhosts/%0.0/htdocs
VirtualScriptAlias /var/www/vhosts/%0.0/cgi-bin
# example.com --> /var/www/vhosts/example.com
# www.example.com --> /var/www/vhosts/www.example.com
# a.www.example.com --> /var/www/vhosts/a.www.example.com
# www.example.com/cgi-bin --> /var/www/vhosts/www.example.com/cgi-bin
#VirtualDocumentRoot /var/www/vhosts/%0.0
#VirtualScriptAlias /var/www/vhosts/%0.0/cgi-bin
# example.com --> /var/www/vhosts/example.com
# www.example.com --> /var/www/vhosts/example.com
# a.www.example.com --> /var/www/vhosts/example.com
# www.example.com/cgi-bin --> /var/www/vhosts/example.com/cgi-bin
#VirtualDocumentRoot /var/www/vhosts/%-2.0.%-1.0
#VirtualScriptAlias /var/www/vhosts/%-2.0.%-1.0/cgi-bin
# example.com --> /var/www/vhosts/example.com/_
# www.example.com --> /var/www/vhosts/example.com/www
# a.www.example.com --> /var/www/vhosts/example.com/a.www
# example.com/cgi-bin --> /var/www/vhosts/example.com/_/cgi-bin
# www.example.com/cgi-bin --> /var/www/vhosts/example.com/a.www/cgi-bin
#VirtualDocumentRoot /var/www/vhosts/%-2.0.%-1.0/%-3+/
#VirtualScriptAlias /var/www/vhosts/%-2.0.%-1.0/%-3+/cgi-bin
# CGI Directives
#
<DirectoryMatch "^/var/www/vhosts/[^/]+/cgi-bin">
AllowOverride None
Options ExecCGI
<IfModule mod_access.c>
Order allow,deny
Allow from all
</IfModule>
</DirectoryMatch>
</IfModule>
</VirtualHost>
</IfDefine>
|
