Monday, January 13, 2014

Apache Virtual Hosts not working? Are you using IP or wildcard?

The Apache virtual host directive starts with something like the below:
<VirtualHost sample.com:80>
  ServerName sample.com
  ...
Basically you need to include the IP or domain of your service with the port where the service is listening to separated by colon. Very often you see the sysadmin suggesting and in fact using the below instead:
<VirtualHost *:80>
  ServerName sample.com
  ...
That is basically saying the Server will listen in all IPs for the specific domain. This will work perfectly for SSL as well until ... a second website is needed.

The reason is that SSL works at IP level and not domain level. That means you cannot have two domains served by the same IP. At that point you need to specify the resolvable domain or the IP.

What happens when you are trying to migrate the existing site to a new server? The IPs will be different but your DNS cannot be changed until the migration is performed. You have no other option than resolving to the future IP in *just* the new server and that is exactly what /etc/hosts is for.
192.168.0.12 sample.com
Without that entry your new server will never work for the existing domain. Of course you need now to remember to remove the entry once the migration has finished.

No comments:

Followers