?
Solved

apache vhost_alias usage alongside regular vhost

Posted on 2010-09-10
1
Medium Priority
?
886 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 1

Accepted Solution

by:
sierratechs earned 1500 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

Video: Liquid Web Managed WordPress Comparisons

If you run run a WordPress, you understand the potential headaches you may face when updating your plugins and themes. Do you choose to update on the fly and risk taking down your site; or do you set up a staging, keep it in sync with your live site and use that to test updates?

Question has a verified solution.

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

Short answer to this question: there is no effective WiFi manager in iOS devices as seen in Windows WiFi or Macbook OSx WiFi management, but this article will try and provide some amicable solutions to better suite your needs.
Most of the applications these days are on Cloud. Cloud is ubiquitous with many service providers in the market. Since it has many benefits such as cost reduction, software updates, remote access, disaster recovery and much more.
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…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

777 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