Solved

apache vhost_alias usage alongside regular vhost

Posted on 2010-09-10
1
883 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

ADCs have gained traction within the last decade, largely due to increased demand for legacy load balancing appliances to handle more advanced application delivery requirements and improve application performance.
For many of us, the  holiday season kindles the natural urge to give back to our friends, family members and communities. While it's easy for friends to notice the impact of such deeds, understanding the contributions of businesses and enterprises i…
After creating this article (http://www.experts-exchange.com/articles/23699/Setup-Mikrotik-routers-with-OSPF.html), I decided to make a video (no audio) to show you how to configure the routers and run some trace routes and pings between the 7 sites…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

820 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