Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

If I type in my server ip address into a browser, it always goes to the lowest alphabetical domain on my server. So if I had these domain on my server:

  • zty.com
  • typ.com
  • dfo.com

...typing in the ip would take you to dfo.com.

If I then add abc.com to my server, typing the the ip in a browser would go to abc.com

How do I make the ip go to the primary domain on the server?

share|improve this question

1 Answer 1

up vote 6 down vote accepted

By using an IP address to access your server you are bypassing the DNS system so this has nothing to do with DNS or Bind.

If you are observing this as the response from a web server and the webserver is apache then my guess is that you are creating vhosts in such a manner that they are defined alphabetically. Without any way to differentiate between vhosts apache will serve the first vhost that was defined as the default vhost.

What you have to do is make your primary domain be defined as the first vhost on the server. If your primary domain is example.com and it is defined in a file called example.com rename the example.com configuration file to something like 000example.com

share|improve this answer
    
What does it have to do with then, and how would I fix it? –  user1248979 May 12 '12 at 7:14
    
Would your idea be better than a2ensite'ing default again, and putting the same DocumentRoot/Directory path as the primary domain? –  user1248979 May 12 '12 at 7:30
1  
Creating a file which obviously comes first alphabetically is the way this is normally handled. Apache picks the first file it can find if the client connects via IP not name - just make your primary domain config file the first one alphabetically, as suggested. –  EightBitTony May 12 '12 at 7:33
    
To clarify this comment a bit, Apache picks the first <NameVirtualHost> it finds for an IP Address that's using name-based virtual hosting. On systems using sites-enabled or a similar directory the contents of that directory are loaded in "ASCIIbetical order" (the order they show up in when you run ls). So the file that's first in the directory listing is loaded earliest, and "wins" by default. –  voretaq7 Mar 7 '13 at 16:28

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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