3

I have a development server for PHP programmers set up and runnig for some time now. The system is Debian with default Apache package:

# apache2 -v
Server version: Apache/2.2.9 (Debian)
Server built:   Dec 11 2010 18:58:55

I have set up about 30 name based VirtualHosts, one for each project and for each developer. I do the configuration with scripts, but now I have to add about 15 new project, all of them with standard directory structure, so I thought, I will use mod_vhost_alias

I have my config similar to this:

NameVirtualHost *:80
#Default vhost
<VirtualHost *:80>
  DocumentRoot /var/www/404
  ServerName dev.example.com
  ErrorLog /var/log/apache2/404.error_log
  TransferLog /var/log/apache2/404.access_log
        <Directory "/var/www/404">
                allow from all
                Options Indexes Includes
                AllowOverride All
        </Directory>
</VirtualHost>
#this entry is repeated many times 
#with different server names, document roots 
# and other differences, bu basics stay the same
<VirtualHost *:80>
  DocumentRoot /var/www/crm
  ServerName crm.dev.example.com
  ErrorLog /var/log/apache2/crm.error_log
  TransferLog /var/log/apache2/crm.access_log
        <Directory "/var/www/crm">
                allow from all
                Options Indexes Includes
                AllowOverride All
        </Directory>
</VirtualHost>

# I added  Vhost_alias virtaul host today, at the end of the config

<VirtualHost *:80>
    # This is for pages similar to some-page.pl.web.example.com
    UseCanonicalName Off
    ServerAlias *.web.dev.example.com
    VirtualDocumentRoot /var/www/web/%-4+/cur
    ErrorLog /var/log/apache2/%-4+.error_log
    TransferLog /var/log/apache2/%-4+.access_log
    <Directory /var/www/%-4+>
        allow from all
        Options Indexes Includes
        AllowOverride All
    </Directory>
</VirtualHost>

The result is, when I connect to http://my-page.com.web.dev.example.com I get the default vhost from /var/www/404 directory. The directory /var/www/web/my-page.com/ exists, and contains copy of my-page.com real webpage.

What am I doing wrong? Do I need separate ip addresses for "standard" NameVirtualHost and for vhost_alias? What else should I check?

2 Answers 2

3

Yes, you can use NameVirtualHost and mod_vhost_alias in the same configuration. Alter your mod_vhost_alias entry like this:

<IfModule mod_vhost_alias.c>
    <VirtualHost *:80>
        ServerAlias *.web.dev.example.com
        VirtualDocumentRoot /var/www/web/%-4+/cur
        ErrorLog /var/log/apache2/%-4+.error_log
        TransferLog /var/log/apache2/%-4+.access_log
        <Directory /var/www/%-4+>
            allow from all
            Options Indexes Includes
            AllowOverride All
        </Directory>
    </VirtualHost>
</IfModule>

Put this entry directly below the line Include conf.d/*.conf in httpd.conf (found at /etc/httpd/conf/httpd.conf on RHEL systems), or in a new file in /etc/apache2/conf-enabled/ for Ubuntu.

edit: I blogged further information.

1

I've setup similar VirtualDocumentRoot-based for wild-card sub-domains before. It's just so useful to be able to create a directory inside someone's home-directory - usually sharing their directory over Samba so that they can be used from the developer's desktop - and you have create a new website - at least for development & testing.

As for your problem, I just put them onto different IP addresses, without a default vhost.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .