Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

apache vhost_alias usage alongside regular vhost

Posted on 2010-09-10
1
Medium Priority
?
887 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I had an issue with InstallShield not being able to use Computer Browser service on Windows Server 2012. Here is the solution I found.
This article is in regards to the Cisco QSFP-4SFP10G-CU1M cables, which are designed to uplink/downlink 40GB ports to 10GB SFP ports. I recently experienced this and found very little configuration documentation on how these are supposed to be confi…
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…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

596 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