Web-server – Apache Configuration – Domain with Hyphen

apache-2.2web-server

Having a strange issue configuring apache.

I've got 4 domains

  • www.mydomain.tld
  • www.my-domain.tld

  • www.anotherdomain.tld

  • www.another-domain.tld

I've configured named virtualhost for each of the domains.

mydomain.tld, my-domain.tld and anotherdomain.tld works correctly but another-domain.tld isn't working correctly.

Apache seems to be picking up the virtualhost for anotherdomain.tld and serving it rather than the another-domain.tld

both have the server name set correctly

  • ServerName anotherdomain.tld

and

  • ServerName another-domain.tld

which seems to be the only place this could be an issue. Does anyone have any suggestion on finding the cause of this error.

A couple of other notes: each virtualhost is in a different file. mydomain.tld and my-domain.tld on a different ip address to anotherdomain.tld and another-domain.tld.

Best Answer

How can you tell that the web server is serving anotherdomain.tld instead of another-domain.tld? Do you see that URL in the browser's address bar has anotherdomain.tld in it?

If you created these configuration with copy-paste technique, then you could have left the DocumentRoot the same for both domains.

Another guess is if anotherdomain.tld and another-domain.tld are configured on the same IP address for apache, but another-domain.tlp DNS "A" record is set up to a different IP, Apache HTTPD just pulls out the default VirtualHost for the IP specified in its configuration, which may be anotherdomain.tld.

Example: If you have in DNS:

 anotherdomain.tld ->  1.2.3.12
 another-domain.tld -> 1.2.3.12

Then in httpd.conf:

<VirtualHost 1.2.3.12:80>
 ServerName anotherdomain.tld
  ...
</VirtualHost

<VirtualHost 1.2.3.18:80>
 ServerName another-domain.tld
  ...
</VirtualHost

When you type http://another-domain.tld/ in the browser's address bar, it makes a request to 1.2.3.12, which pulls out the default virtual host for 1.2.3.12, which is anotherdomain.tld.

These are just two wild guesses though...

Related Topic