Link to home
Start Free TrialLog in
Avatar of Michael Worsham
Michael WorshamFlag for United States of America

asked on

Dynamic virthosts

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.

Listen 123.456.789.012:80
VirtualHost dev.mysite.com>
   ServerName dev.mysite.com
   DocumentRoot /web/sandbox.domainname.com/dev.mysite.com/htdocs
   ErrorLog /var/web/sandbox.domainname.com/dev.mysite.com_error_log
   CustomLog /var/web/sandbox.domainname.com/dev.mysite.com_access_log common
   ScriptAlias /cgi-bin/ "/web/sandbox.domainname.com/dev.mysite.com/cgi-bin/"
   <Directory /web/sandbox.domainname.com/dev.mysite.com>
      Options Indexes FollowSymLinks Multiviews +Includes
      AllowOverride All
   </Directory>
</VirtualHost>


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 CNAME like: sandbox.domainname.com

     Example:
      - dev.mysite.com would point to /web/sandbox.domainname.com/dev.mysite.com
      - dev2.mysite.com would point to /web/sandbox.domainname.com/dev2.mysite.com

And so on.

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.

Apache Version: 2.0.52 (Red Hat)
PHP Version 5.1.2

Loaded Modules: core prefork http_core mod_so mod_access mod_auth mod_auth_anon mod_auth_dbm mod_auth_digest util_ldap mod_auth_ldap mod_include mod_log_config mod_env mod_mime_magic mod_cern_meta mod_expires mod_deflate mod_headers mod_usertrack mod_setenvif mod_mime mod_dav mod_status mod_autoindex mod_asis mod_info mod_dav_fs mod_vhost_alias mod_negotiation mod_dir mod_imap mod_actions mod_speling mod_userdir mod_alias mod_rewrite mod_proxy proxy_ftp proxy_http proxy_connect mod_cache mod_suexec mod_disk_cache mod_file_cache mod_mem_cache mod_cgi mod_php5 mod_ssl

-- Michael
Avatar of northcide
northcide

i believe mod_rewrite can do what you want but i cannot help with creating those expressions.  wouldnt it be much simpler to just append folder names to the end of a url like dev.mydomain.com/devsite1/?

I've messed with this on my development servers a bunch and i've found that the new folder method is the simplest and does what i need it to do.  just a thought.
Avatar of Michael Worsham

ASKER

Actually that is what we are looking to do as seen in the original question, but don't know what we need to do with the mod_rewrite to pass the site to that address. Is it possible to have something like a /web/sandbox.domainname.com/$requested_url/htdocs in the Virthosts * entry or ?

Web Browser URL --> dev.mysite.com

DNS sees the request for dev.mysite.com and resolves it to sandbox.domainname.com

Linux Apache/PHP instance sees a request for dev.mysite.com and points the user to /web/sandbox.domainname.com/dev.mysite.com/htdocs

The type of sites that are being built out are Joomla and Drupal sites.
funny, we do the same mass production with joomla and drupal.

so are your virtual sites arent working at all?  your hostname never changes right?  so you have http://thisdoesntchange.thisdoesnteaither.com/thischangesallthetime/?

Right now we have the following built out as out virthosts-sandbox.conf:

NameVirtualHost 111.222.333.444
Listen 111.222.333.444:80
<VirtualHost 111.222.333.444>
   ServerName sandbox.domainname.com
   DocumentRoot /web/sandbox.domainname.com
   ErrorLog /var/web/sandbox.domainname.com/error_log
   CustomLog /var/web/sandbox.domainname.com/access_log common
   ScriptAlias /cgi-bin/ "/web/sandbox.domainname.com/"
   <Directory /web/sandbox.domainname.com>
      Options Indexes FollowSymLinks Multiviews +Includes
      AllowOverride All
   </Directory>

   RewriteEngine on
   RewriteRule ^(.*)$ http://sandbox.domainname.com/$1 [L,R]
</VirtualHost>

We just don't know where to go from here as we have always built out sites, placing their name in the VirtHosts entry (i.e. <VirtHosts dev.mysite.com>, etc).
ASKER CERTIFIED SOLUTION
Avatar of northcide
northcide

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I don't think its possible to comment out the Listen portion as we have several other httpd's running on the same box for other departments.

I tried to modify the NameVirtualHost, and I get this error upon '/etc/init.d/http-sandbox configtest':

[Thu Aug 09 08:31:14 2007] [error] VirtualHost _default_:443 -- mixing * ports and non-* ports with a NameVirtualHost address is not supported, proceeding with undefined results
Nevermind. I got that part working. Had to modify one other file.

Now I just need the Rewrite Cond and Rules. Currently I have (which is probably not right):

   RewriteEngine on
   RewriteCond %{HTTP_HOST} ^([^\.]+)\.sandbox\.domainname\.com$ [NC]
   RewriteCond %{HTTP_HOST} !^$
   RewriteRule ^(.*)$ http://sandbox.domainname.com/$1/htdocs [R]

I just need the path to resolve to http://sandbox.domainname.com/mysitename.com.

Also posted this message on another site (http://forum.modrewrite.com) and someone posted about using mod_vhost_alias instead to do what I was looking for. After a bit of research, I stumbled upon this site:

http://eising.wordpress.com/2006/05/01/using-mod_vhost_alias-and-normal-virtualhosts-on-the-same-time/

-- M