Dynamic virthost

Using a single web hosting account to host multiple sites

Dynamic virthost

Postby mwe » Fri Aug 10, 2007 7:30 am

Here is the issue.

We are working on giving our developers a 'sandbox' where they can create new sites under a base directory structure we have setup for them. The problem is the sites change from day to day, based on their site name and its a real issue for us to have to keep modifying the virthosts-sandbox.conf file for each site name change.

Is it possible to use the Rewrite Engine (or any other module) to just direct the site instead, based on what the DNS entry is seen as? Our DNS points each site to a universal CNAME (sandbox.domainname.com).

DNS db.domain.com entry:

Code: Select all
sandbox1       IN    CNAME   sandbox.domain.com


Current virthosts-sandbox.conf file:

Code: Select all
NameVirtualHost *:80

Listen 111.222.333.444:80

<VirtualHost *:80>
   ServerName sandbox.domain.com
   DocumentRoot /web/sandbox.domain.com
   ErrorLog /var/web/sandbox.domain.com/error_log
   CustomLog /var/web/sandbox.domain.com/access_log common
   <Directory /web/sandbox.domain.com>
      Options Indexes +FollowSymLinks Multiviews +Includes
      AllowOverride All
   </Directory>
</VirtualHost>


Under the /web/sandbox.domain.com directory, the .htaccess file:

Code: Select all
Options +FollowSymLinks
RewriteEngine On

RewriteBase /web/sandbox.domain.com/
RewriteCond %{HTTP_HOST} ^(sandbox\.)?((domain)\.com)$ [NC]
RewriteRule ^(.*)$ http://sandbox.domain.com/$1/htdocs [R=301,L]


Server-Side Directory Structure

Code: Select all
/web/sandbox.domain.com
drwxr-xr-x  7 www content 4096 Aug  7 15:58 sandbox1.domain.com

/web/sandbox.domain.com/sandbox1.domain.com
drwxr-xr-x  2 www content 4096 Aug  7 15:58 cgi-bin
drwxr-xr-x  2 www content 4096 Aug  7 16:28 htdocs
drwxr-xr-x  2 www content 4096 Aug  7 15:58 working

/web/sandbox.domain.com/sandbox1.domain.com/htdocs
-rw-r--r--  1 www content      21 Aug  7 16:28 index.php


The idea is that when a developer tries to go sandbox1.domain.com, the instance will actually redirect them to http://sandbox.domain.com/sandbox1.domain.com instead.

We just don't want to have to keep modifying the virthosts-sandbox.conf for each new domain name being addressed. We are talking about several hundred sites found in the virthosts-sandbox.conf file, thus the reason for the request.

-- Michael
mwe
 
Posts: 21
Joined: Fri Aug 10, 2007 7:12 am
Location: North Augusta, SC USA

Postby richardk » Fri Aug 10, 2007 3:24 pm

Is it possible to use the Rewrite Engine (or any other module) to just direct the site instead, based on what the DNS entry is seen as? Our DNS points each site to a universal CNAME (sandbox.domainname.com).

I don't think mod_rewrite or any other module can check if a domain is a CNAME of another.

Do you have other sub domains (that aren't sandboxes) on the server?

With mod_rewrite you could create a text or dbm file and use a RewriteMap to find if it was a sandbox or not, however you couldn't put it in that <VirtualHost> as it only matches sandbox.domain.com.

There's also mod_vhost_alias.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby mwe » Tue Aug 14, 2007 5:25 am

Thanks for the idea. Found a site that did exactly what I was looking for:

http://eising.wordpress.com/2006/05/01/ ... same-time/

-- M
mwe
 
Posts: 21
Joined: Fri Aug 10, 2007 7:12 am
Location: North Augusta, SC USA


Return to Domain Handling

Who is online

Users browsing this forum: No registered users and 43 guests

cron