Dynamic Virtualhosting (for subdomains) with apache
Apache provides a very easy method to provide hosting for dynamically created sub-domains with "VirtualScriptAlias" and "VirtualDocumentRoot" syntaxes
Lets say, we have mydomain.com, and you need to dynamically configure test.mydomain.com, monkey.mydomain.com etc. (and not required to manually configure apache or restart), then..
Step 1: Configure wild-card DNS, so that *.mydomain.com is a cname to mydomain.com
Step 2: Configure apache. Create a new virtualhost section for *.mydomain.com, like:
<VirtualHost *>
ServerAlias *.mydomain.com
CustomLog /www/www.logs/virtual.mydomain.com-access_log combined
ErrorLog /www/www.logs/virtual.mydomain.com-error_log
VirtualDocumentRoot /www/www.mydomain.com/virtualdomains/%0/docs
VirtualScriptAlias /www/www.mydomain.com/virtualdomains/%0/cgi-bin/
</VirtualHost>
Step 3: Restart apache to activate the new configuration
Step 4: Now, say you need test.mydomain.com, all that is required is to create /www/www.mydomain.com/virtualdomains/test.mydomain.com/docs and /www/www.mydomain.com/virtualdomains/test.mydomain.com/cgi-bin/
Technorati Tags: apache, dynamic, subdomain, virtualhosting
0 TrackBacks
Listed below are links to blogs that reference this entry: Dynamic Virtualhosting (for subdomains) with apache.
TrackBack URL for this entry: http://www.megalinux.net/cgi-bin/mt/mt-tb.fcgi/72

Leave a comment