VirtualHost not directing properly based on domain name

We recently moved from name-based hosting to individual IPs for an SSL implementation. Thus, each website now has its own IP. While www.domain1.com and www.domain2.com are being directed to the correct directories on the server, subdomains such as dev.domain1.com and dev.domain2.com are not. The subdomains also have their own IPs. Here's the structure of one of the subdomain's .conf files:

<VirtualHost 1.2.3.4:80>
    ServerAdmin [email protected]
    DocumentRoot /var/www/domain1-dev
    ServerName dev.domain1.com
    ServerAlias dev.domain2.com
    ErrorLog logs/dev.domain1.com-error.log
    CustomLog logs/dev.domain1.com-access.log common

    <Directory /var/www/domain1-dev>
      Options Indexes FollowSymLinks
      AllowOverride All
      Order allow,deny
      Allow from all
    </Directory>
</VirtualHost>

ServerName is currently commented out and UseCanonicalName is set to be off in the main httpd.conf file. DocumentRoot is set to domain1's path in this httpd.conf file, as is the directive. NameVirtualHost is commented out as we're now on ip-based hosting.

Any idea what could be wrong? :-( It's almost as if subdomain .conf files aren't being read, or else the main domain's settings are being used instead. In fact, any subdomain I type is showing the primary domain's website, even if its not defined under a .conf file.

Thanks much.

EDIT

Here's what I get when running /usr/sbin/httpd -S:

# /usr/sbin/httpd -S
httpd: apr_sockaddr_info_get() failed for the.servername.com
httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
VirtualHost configuration:
1.2.3.5:80        www.domain2.com (/etc/httpd/conf.d/domain2.conf:10)
1.2.3.5:443       www.domain2.com (/etc/httpd/conf.d/ssl.conf:87)
1.2.3.3:80        www.domain1.com (/etc/httpd/conf.d/domain1.conf:1)
1.2.3.3:443       www.domain1.com (/etc/httpd/conf.d/ssl.conf:45)
1.2.3.6:80        dev.domain1.com (/etc/httpd/conf.d/domain1-dev.conf:1)
Syntax OK

EDIT

Here's the syntax for each domain:

<VirtualHost 1.2.3.3:80>
    ServerAdmin [email protected]
    DocumentRoot /var/www/html
    ServerName www.domain1.com
    ServerAlias domain1.com
    ErrorLog logs/www.domain1.com-error.log
    CustomLog logs/www..domain1.com-access.log common
</VirtualHost>

Solution 1:

I don't see any issue with the VirtualHost config here, but it's pretty possible that even with that apache will choose the wrong one, just to give you some insight to help fix your issue

  • apache will always read the VirtualHosts in order
  • It'll choose which one accomodates better yours needs based on that
  • If you have any ServerAlias *.domain anything assigned to your domain after that is dead, always put the glob aliases at the end

Hope this helps you a bit!

Solution 2:

Running

$PATH_TO_APACHE_DIR/bin/httpd -t -D DUMP_VHOSTS
or 
$PATH_TO_APACHE_DIR/bin/httpd -S

to see what VirtualHosts are recognized and in what files might help. Run "httpd -h" to see a list of other options to show settings.