Apache Virtual Hosts and Multiple IP Addresses
Here's a pain in the ass issue if you're exhausted, it's 4am, and you can't see straight. If you make a weird error with this either subdomains for anything but the first IP address won't work, or incorrect subdomains on secondary IPs will still resolve to the first specified IP's default VirtualHost definition. Or some other unexpected behaviour that will drive you insane while you question DNS, Browser, and OS caching mechanisms and resolvers which most likely have nothing to do with the issue.
Things to remember.
The ServerAlias line should only be one line. Each alias needs to be separated by a space.
The first defined VirtualHost for a given IP is that IP's default.
Make sure ports.conf and httpd.conf are included in Apache2.conf
ports.conf should look like this:
NameVirtualHost 55.11.515.151:80 NameVirtualHost 88.22.828.279:80 Listen 80
and httpd.conf should look like this:
#turn off indexing globally Options -IndexesDocumentRoot /serv/sites/domain.com/public ServerName domain.com ServerAlias www.domain.com DocumentRoot /serv/sites/sub.domain.com/public ServerName sub.domain.com DocumentRoot /serv/sites/domain2.com/public ServerName domain2.com ServerAlias www.domain2.com domain3.com *.domain3.com DocumentRoot /serv/sites/sub.domain2.com/public ServerName sub.domain2.com
1 Comment | Jan 24, 2011