1

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 blah@domain.com
    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 webmaster@domain1.com
    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>
2
  • Are you sure that dns for dev.domain1.com and dev.domain2.com point to 1.2.3.6? Feb 2, 2011 at 22:50
  • Yes, dev.domain1.com points to 1.2.3.6. Good check. We're not currently using dev.domain2.com, but will in the future.
    – MattB
    Feb 3, 2011 at 17:19

3 Answers 3

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!

5
  • Thanks. Here's the line in httpd.conf that reads the individual .conf files: "Include conf.d/*.conf". The individual .conf files are listed in the correct order I believe, with domain1-dev coming after domain1 in the alphabetical file order. Would you have any suggestions on how to check how Apache is reading these .conf files once loaded? I'm unsure why the ServerAlias is there. Old admin must have thought it important. I'll move it to the end of the subdomain conf file.
    – MattB
    Feb 2, 2011 at 17:50
  • Yes! In order to get it right, just rename the one having the catchall ServerAlias to zzz_whatever.conf, it'll read the files in alphabetical order so you have some leeway there
    – lynxman
    Feb 2, 2011 at 17:54
  • Added an example of the domain .conf file. Should there only be one ServerAlias and it resides in the last .conf file? Right now each .conf has it's own ServerAlias.
    – MattB
    Feb 2, 2011 at 18:58
  • Nope, it's just a question of ordering, as you see the last config is the dev file so the other ones take precedence
    – lynxman
    Feb 2, 2011 at 23:13
  • Looks like it worked! Thanks a ton. I ended up renaming domain1-dev.conf to dev-domain1.conf. The solution was so simple and I was making it more complex than needed.
    – MattB
    Feb 4, 2011 at 13:01
1

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.

1
  • Added httpd -S output to my question. Thanks. Based on what I'm seeing, it should be working, unless domain1-dev.conf should be listed first. :-/
    – MattB
    Feb 2, 2011 at 18:51
0

For work name-based hosts on more than one IP address, use

NameVirtualHost IP:80

in your output httpd -S no "NameVirtualHosts".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.