• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 890
  • Last Modified:

apache vhost_alias usage alongside regular vhost

I have a development site I am trying to configure to use the dynamic virtual host with mod_vhost_alias and also allow the IP of the server to be served from a different directory than the vhost configuration.  This is problematic because we only have on IP address and we do not want to involve additional ports.  The idea is that multiple virtual hosts are configuring use the source control structure so that various developers have their own development environment under the source control.  As such, vhost_alias is setup to process these requests based on the [git] source control directory structure.

This works fine, but the production/stable version from the source control also needs to be accessed from this server, but obviously would not be processed by the development structure.  The production is different because there is not a separate host for each developer, just one single host to handle all of production.  Therefore, it needs a separate location.

The structure is similar to:

/sites/dev/ryan/public
/sites/dev/john/public
/sites/dev/tom/public

In this example mod_vhost_alias is configured to serve all reqests to the domain in the form of "ryan.domain.local" to the "/sites/dev/ryan/public" directory.  The same would apply to the other developers and this is expandable to any number of developers who would be added to the source control.

Production would be something like:
/sites/production/version0/public

Since we do not have an actual domain for this testing environment, we are using a local (via hosts file) naming technique.  Therefore, we want the IP of the server to be served as the production version.  So accessing http://124.124.124.124 as the IP of the server would be be served from "/sites/production/version0/public/" in apache.  I'm including the apache directives below, which I know don't work because the production folder is served for all requests, instead of the development folder being served for matches to *.groupmatch.local (the chosen TLD nameholder).

What can I do to get apache to server dynamic vhost requests in one folder structure and have just one other host configured to serve based on the IP address from the production folder?  Thanks in advance for all your help.

For the code below, the first VirtualHost is configured to use mod_vhost_alias, and this works fine.  When the second VirtualHost is added, the first using vhost_alias is ignored, but the IP address works and serves the right folder.
#See this first VirtualHost uses vhost_alias (VirtualDocumentRoot), and this works if the below VirtualHost is removed
<VirtualHost *:80>
        ServerAdmin webmaster@localhost
        ServerName groupmatch.local
        ServerAlias *.groupmatch.local
        UseCanonicalName Off
        VirtualDocumentRoot /sites/development/%-3+/public/
        <Directory /sites/>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride all
                Order allow,deny
                allow from all
        </Directory>

        ErrorLog /var/log/apache2/error.log

        # Possible values include: debug, info, notice, warn, error, crit,
        # alert, emerg.
        LogLevel warn

        CustomLog /var/log/apache2/access.log combined


        ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
        <Directory "/usr/lib/cgi-bin">
                AllowOverride None
                Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
                Order allow,deny
                Allow from all
        </Directory>

    Alias /doc/ "/usr/share/doc/"
    <Directory "/usr/share/doc/">
        Options Indexes MultiViews FollowSymLinks
        AllowOverride None
        Order deny,allow
        Deny from all
        Allow from 127.0.0.0/255.0.0.0 ::1/128
    </Directory>
</VirtualHost>


#by adding this VirtualHost, the IP works and serves from the right location, but overrides the above vhost_alias directives
<VirtualHost 156.56.35.66:80>
        ServerAdmin webmaster@localhost
        ServerName 156.56.35.66
        UseCanonicalName Off
        DocumentRoot /sites/production/version0/public/

        <Directory />
                Options Indexes FollowSymLinks MultiViews
                AllowOverride all
                Order allow,deny
                allow from all
        </Directory>

        ErrorLog /var/log/apache2/error.log

        # Possible values include: debug, info, notice, warn, error, crit,
        # alert, emerg.
        LogLevel warn

        CustomLog /var/log/apache2/access.log combined


        ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
        <Directory "/usr/lib/cgi-bin">
                AllowOverride None
                Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
                Order allow,deny
                Allow from all
        </Directory>

    Alias /doc/ "/usr/share/doc/"
    <Directory "/usr/share/doc/">
        Options Indexes MultiViews FollowSymLinks
        AllowOverride None
        Order deny,allow
        Deny from all
        Allow from 127.0.0.0/255.0.0.0 ::1/128
    </Directory>
</VirtualHost>

Open in new window

0
dageyra
Asked:
dageyra
1 Solution
 
sierratechsCommented:
Use this code in your .htaccess to rewite directories to subdirectories on the web.

<IfModule mod_rewrite.c>
   Options +FollowSymLinks
   Options +Indexes
   RewriteEngine On
   RewriteBase /
   RewriteCond %{HTTP_HOST} !www.domain.com$ [NC]
   RewriteCond %{HTTP_HOST} ^(www.)?([a-z0-9-]+).domain.com [NC]
   RewriteRule (.*) %2/$1 [L]
</IfModule>
0

Featured Post

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.

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