[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 234
  • Last Modified:

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
0
Michael Worsham
Asked:
Michael Worsham
  • 5
  • 3
1 Solution
 
northcideCommented:
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.
0
 
Michael WorshamInfrastructure / Solutions ArchitectAuthor Commented:
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.
0
 
northcideCommented:
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/?

0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
Michael WorshamInfrastructure / Solutions ArchitectAuthor Commented:
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).
0
 
northcideCommented:
you're using ip based virtual hosts when you should be using name based virtual hosts. there are other ways to keep the url in there but name based virtual hosts are a good idea moving forward for you.  comment out all the rewrite stuff....

change the following directives to.....


NameVirtualHost *
<VirtualHost *:80>

comment out....
Listen 111.222.333.444:80

0
 
Michael WorshamInfrastructure / Solutions ArchitectAuthor Commented:
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
0
 
Michael WorshamInfrastructure / Solutions ArchitectAuthor Commented:
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.

0
 
Michael WorshamInfrastructure / Solutions ArchitectAuthor Commented:
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
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now