Solved

apache vhost_alias usage alongside regular vhost

Posted on 2010-09-10
1
880 Views
Last Modified: 2013-12-14
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
Comment
Question by:dageyra
1 Comment
 
LVL 1

Accepted Solution

by:
sierratechs earned 500 total points
ID: 33739394
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Let’s list some of the technologies that enable smooth teleworking. 
PRTG Network Monitor lets you monitor your bandwidth usage, so you know who is using up your bandwidth, and what they're using it for.
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now